Skip to content

Commit 1eaf74e

Browse files
committed
initial commit
0 parents  commit 1eaf74e

File tree

18 files changed

+6865
-0
lines changed

18 files changed

+6865
-0
lines changed

.eslintrc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"parser": "@typescript-eslint/parser",
3+
"extends": [
4+
"eslint:recommended",
5+
"@typescript-eslint/recommended"
6+
],
7+
"plugins": ["@typescript-eslint"],
8+
"parserOptions": {
9+
"ecmaVersion": 2022,
10+
"sourceType": "module"
11+
},
12+
"rules": {
13+
"@typescript-eslint/no-unused-vars": "error",
14+
"@typescript-eslint/no-explicit-any": "warn",
15+
"@typescript-eslint/explicit-function-return-type": "off",
16+
"@typescript-eslint/explicit-module-boundary-types": "off",
17+
"@typescript-eslint/no-non-null-assertion": "warn",
18+
"prefer-const": "error",
19+
"no-var": "error"
20+
},
21+
"env": {
22+
"node": true,
23+
"es2022": true
24+
}
25+
}

.github/workflows/test.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Test Action
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '20'
22+
cache: 'npm'
23+
24+
- name: Install dependencies
25+
run: npm ci
26+
27+
- name: Lint code
28+
run: npm run lint
29+
30+
- name: Build action
31+
run: npm run build
32+
33+
- name: Package action
34+
run: npm run package
35+
36+
- name: Test action (dry run)
37+
uses: ./
38+
with:
39+
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN || 'test-token' }}
40+
repo: test-repo
41+
branch: test-branch
42+
continue-on-error: true

.gitignore

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Build outputs
8+
dist/
9+
build/
10+
*.tsbuildinfo
11+
12+
# Environment variables
13+
.env
14+
.env.local
15+
.env.development.local
16+
.env.test.local
17+
.env.production.local
18+
19+
# IDE/Editor files
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# OS generated files
27+
.DS_Store
28+
.DS_Store?
29+
._*
30+
.Spotlight-V100
31+
.Trashes
32+
ehthumbs.db
33+
Thumbs.db
34+
35+
# Logs
36+
logs/
37+
*.log
38+
39+
# Coverage directory (Jest)
40+
coverage/
41+
*.lcov
42+
43+
# Cache directories
44+
.cache/
45+
.eslintcache
46+
.npm
47+
48+
# Temporary files
49+
tmp/
50+
temp/
51+
*.tmp
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "es5",
4+
"singleQuote": true,
5+
"printWidth": 100,
6+
"tabWidth": 2,
7+
"useTabs": false
8+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 LaunchDarkly
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# LaunchDarkly Delete Branch Action
2+
3+
A GitHub Action that automatically deletes branches from LaunchDarkly Code References when they are deleted in GitHub.
4+
5+
## Features
6+
7+
- 🚀 **Automatic branch deletion** - Deletes LaunchDarkly Code Refs branches when GitHub branches are deleted
8+
- 🔄 **Retry logic** - Built-in retry mechanism for handling rate limits and transient errors
9+
-**Fast execution** - Optimized for quick branch cleanup
10+
- 🛡️ **Error handling** - Comprehensive error handling with detailed logging
11+
- 🔧 **Configurable** - Flexible configuration options for different environments
12+
13+
## Usage
14+
15+
### Basic Usage
16+
17+
```yaml
18+
name: Delete LaunchDarkly Branch
19+
on:
20+
delete:
21+
branches: [main, develop, feature/*]
22+
23+
jobs:
24+
delete-ld-branch:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Delete LaunchDarkly Code Refs Branch
28+
uses: your-org/launchdarkly-delete-branch-action@v1
29+
with:
30+
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}
31+
```
32+
33+
### Advanced Usage
34+
35+
```yaml
36+
name: Delete LaunchDarkly Branch
37+
on:
38+
delete:
39+
branches: [main, develop, feature/*]
40+
41+
jobs:
42+
delete-ld-branch:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- name: Delete LaunchDarkly Code Refs Branch
46+
uses: your-org/launchdarkly-delete-branch-action@v1
47+
with:
48+
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}
49+
repo: my-custom-repo-key
50+
branch: ${{ github.ref_name }}
51+
base-uri: https://app.launchdarkly.com
52+
```
53+
54+
## Inputs
55+
56+
| Input | Description | Required | Default |
57+
|-------|-------------|----------|---------|
58+
| `access-token` | LaunchDarkly API access token with Code References permissions | ✅ | - |
59+
| `repo` | Repository key in LaunchDarkly | ❌ | GitHub repository name |
60+
| `branch` | Branch name to delete | ❌ | Deleted branch from GitHub event |
61+
| `base-uri` | LaunchDarkly base URI | ❌ | `https://app.launchdarkly.com` |
62+
63+
## Setup
64+
65+
### 1. Create a LaunchDarkly Access Token
66+
67+
1. Go to your LaunchDarkly dashboard
68+
2. Navigate to Account Settings > Access Tokens
69+
3. Create a new token with Code References permissions
70+
4. Copy the token value
71+
72+
### 2. Add the Token to GitHub Secrets
73+
74+
1. Go to your GitHub repository
75+
2. Navigate to Settings > Secrets and variables > Actions
76+
3. Click "New repository secret"
77+
4. Name: `LAUNCHDARKLY_ACCESS_TOKEN`
78+
5. Value: Your LaunchDarkly access token
79+
80+
### 3. Create the Workflow
81+
82+
Create a `.github/workflows/delete-ld-branch.yml` file in your repository:
83+
84+
```yaml
85+
name: Delete LaunchDarkly Branch
86+
on:
87+
delete:
88+
branches: [main, develop, feature/*]
89+
90+
jobs:
91+
delete-ld-branch:
92+
runs-on: ubuntu-latest
93+
steps:
94+
- name: Delete LaunchDarkly Code Refs Branch
95+
uses: your-org/launchdarkly-delete-branch-action@v1
96+
with:
97+
access-token: ${{ secrets.LAUNCHDARKLY_ACCESS_TOKEN }}
98+
```
99+
100+
## How It Works
101+
102+
1. **Trigger**: The action is triggered when a branch is deleted in GitHub
103+
2. **Detection**: It automatically detects the deleted branch name and repository
104+
3. **API Call**: Makes a POST request to LaunchDarkly's Code References API
105+
4. **Retry Logic**: Implements exponential backoff for rate limits and transient errors
106+
5. **Confirmation**: Logs success or failure of the operation
107+
108+
## Error Handling
109+
110+
The action includes comprehensive error handling:
111+
112+
- **Rate Limiting**: Automatically retries with exponential backoff when hitting rate limits
113+
- **Transient Errors**: Retries on 5xx server errors
114+
- **Network Issues**: Handles network timeouts and connection errors
115+
- **Validation**: Validates required inputs and GitHub context
116+
117+
## Retry Logic
118+
119+
The action implements intelligent retry logic:
120+
121+
- **Max Retries**: 5 attempts by default
122+
- **Base Delay**: 1 second initial delay
123+
- **Exponential Backoff**: Doubles delay on each retry
124+
- **Rate Limit Headers**: Respects `Retry-After` and `X-Ratelimit-Reset` headers
125+
- **Transient Errors**: Only retries on 429 and 5xx status codes
126+
127+
## Development
128+
129+
### Prerequisites
130+
131+
- Node.js 18+
132+
- npm or yarn
133+
134+
### Setup
135+
136+
```bash
137+
# Install dependencies
138+
npm install
139+
140+
# Build the action
141+
npm run build
142+
143+
# Package for distribution
144+
npm run package
145+
```
146+
147+
### Scripts
148+
149+
- `npm run build` - Compile TypeScript
150+
- `npm run package` - Package for distribution using @vercel/ncc
151+
- `npm run lint` - Run ESLint
152+
- `npm run format` - Format code with Prettier
153+
- `npm test` - Run tests
154+
155+
## License
156+
157+
MIT License - see [LICENSE](LICENSE) file for details.
158+
159+
## Contributing
160+
161+
1. Fork the repository
162+
2. Create a feature branch
163+
3. Make your changes
164+
4. Add tests if applicable
165+
5. Submit a pull request
166+
167+
## Support
168+
169+
For issues and questions:
170+
171+
1. Check the [Issues](https://github.com/your-org/launchdarkly-delete-branch-action/issues) page
172+
2. Create a new issue with detailed information
173+
3. Include logs and error messages when possible

0 commit comments

Comments
 (0)