Skip to content

Commit 7f411c7

Browse files
committed
add function to create issue for expired flags
1 parent b7fc6e2 commit 7f411c7

File tree

7 files changed

+4720
-61
lines changed

7 files changed

+4720
-61
lines changed

.github/workflows/test.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ jobs:
3333
integration-test:
3434
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
3535
runs-on: ubuntu-latest
36+
permissions:
37+
issues: write
38+
contents: read
3639
steps:
3740
- uses: actions/checkout@v4
3841

39-
- name: Test the action
42+
- name: Test the action with issue creation
4043
uses: ./
4144
with:
4245
launchdarkly_api_key: ${{ secrets.LAUNCHDARKLY_API_KEY }}
4346
project_key: ${{ vars.TEST_PROJECT_KEY || 'test-project' }}
4447
days_ahead: '30'
4548
include_past_due: 'true'
49+
create_issues: 'true'
50+
github_token: ${{ secrets.GITHUB_TOKEN }}
4651

ISSUE_TEMPLATE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 🚨 Expired LaunchDarkly Feature Flag: {{flagName}}
2+
3+
## Flag Details
4+
- **Flag Name**: `{{flagName}}`
5+
- **Flag Key**: `{{flagKey}}`
6+
- **Expired Date**: {{expiryDate}}
7+
- **Days Overdue**: {{daysOverdue}} days
8+
9+
## Action Required
10+
This feature flag has expired and should be reviewed for cleanup.
11+
12+
### Cleanup Steps
13+
- [ ] Review flag usage in codebase
14+
- [ ] Verify flag is no longer needed
15+
- [ ] Remove flag references from code
16+
- [ ] Archive flag in LaunchDarkly
17+
- [ ] Close this issue
18+
19+
### Context
20+
This issue was automatically created by the [LaunchDarkly Feature Flag Expiry Audit Action](https://github.com/{{repoOwner}}/{{repoName}}/actions).
21+
22+
**Project**: {{projectKey}}
23+
**Audit Date**: {{auditDate}}
24+
25+
---
26+
⚠️ **Important**: Please review this flag's usage before deletion to avoid breaking functionality.

README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ A GitHub Action that audits LaunchDarkly feature flags with expiry dates stored
1010
- 📊 **Comprehensive Reporting**: Generates detailed summaries with flag names, keys, and expiry information
1111
- 🚨 **Past Due Identification**: Optionally includes flags that are already past their expiry date
1212
- 📝 **Multiple Date Formats**: Supports various date formats (MM/DD/YYYY, YYYY-MM-DD, etc.)
13+
- 🎫 **Automated Issue Creation**: Optionally creates GitHub issues for expired flags with task labels
1314

1415
## Usage
1516

@@ -152,6 +153,34 @@ jobs:
152153
});
153154
```
154155
156+
### Using with Automatic Issue Creation
157+
158+
```yaml
159+
name: Flag Cleanup with Issue Creation
160+
on:
161+
schedule:
162+
- cron: '0 9 * * 1' # Monday at 9 AM
163+
164+
jobs:
165+
audit-and-create-issues:
166+
runs-on: ubuntu-latest
167+
permissions:
168+
issues: write
169+
contents: read
170+
steps:
171+
- uses: actions/checkout@v4
172+
173+
- name: Audit flags and create issues
174+
uses: your-org/ld-cp-exp-date-gh-actions-audit@v1
175+
with:
176+
launchdarkly_api_key: ${{ secrets.LAUNCHDARKLY_API_KEY }}
177+
project_key: 'my-project'
178+
days_ahead: '7'
179+
include_past_due: 'true'
180+
create_issues: 'true'
181+
github_token: ${{ secrets.GITHUB_TOKEN }}
182+
```
183+
155184
## Inputs
156185
157186
| Input | Description | Required | Default |
@@ -160,7 +189,9 @@ jobs:
160189
| `project_key` | LaunchDarkly project key | Yes | |
161190
| `days_ahead` | Number of days ahead to check for expiring flags | No | `7` |
162191
| `include_past_due` | Include flags that are past their expiry date | No | `true` |
163-
| `custom_property_key` | Name of the custom property containing the expiry date | No | `flag.expiry.date` |
192+
| `custom_property_name` | Name of the custom property containing the expiry date | No | `flag.expiry.date` |
193+
| `create_issues` | Create GitHub issues for expired flags | No | `false` |
194+
| `github_token` | GitHub token for creating issues | No | `${{ secrets.GITHUB_TOKEN }}` |
164195

165196
## Outputs
166197

@@ -208,6 +239,39 @@ The action supports multiple date formats:
208239
- `YYYY-MM-DD` (e.g., `2024-03-15`)
209240
- `YYYY/MM/DD` (e.g., `2024/03/15`)
210241

242+
## GitHub Issue Creation
243+
244+
The action can automatically create GitHub issues for expired flags using the `create_issues: 'true'` option.
245+
246+
### Issue Template
247+
248+
The action looks for an `ISSUE_TEMPLATE.md` file in your repository root. If not found, it uses a built-in template. You can customize the template with these placeholders:
249+
250+
- `{{flagName}}` - The display name of the flag
251+
- `{{flagKey}}` - The flag key
252+
- `{{expiryDate}}` - The expiry date
253+
- `{{daysOverdue}}` - Number of days past expiry
254+
- `{{projectKey}}` - LaunchDarkly project key
255+
- `{{auditDate}}` - Date the audit was run
256+
- `{{repoOwner}}` - Repository owner
257+
- `{{repoName}}` - Repository name
258+
259+
### Issue Features
260+
261+
- **Duplicate Prevention**: Checks for existing open issues before creating new ones
262+
- **Auto-labeling**: Issues are labeled with `launchdarkly`, `expired-flag`, and `task`
263+
- **Task Checklist**: Includes cleanup steps as checkboxes
264+
- **Context Information**: Provides all necessary details for flag cleanup
265+
266+
### Required Permissions
267+
268+
To create issues, your workflow needs:
269+
```yaml
270+
permissions:
271+
issues: write
272+
contents: read
273+
```
274+
211275
## API Requirements
212276

213277
### LaunchDarkly API Token

action.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ inputs:
1818
required: false
1919
default: 'true'
2020
custom_property_key:
21-
description: 'Name of the custom property containing expiry date (default: flag.expiry.date)'
21+
description: 'Key of the custom property containing expiry date (default: flag.expiry.date)'
2222
required: false
2323
default: 'flag.expiry.date'
24+
create_issues:
25+
description: 'Create GitHub issues for expired flags (default: false)'
26+
required: false
27+
default: 'false'
28+
github_token:
29+
description: 'GitHub token for creating issues (defaults to GITHUB_TOKEN)'
30+
required: false
2431

2532
outputs:
2633
expiring_flags:

dist/ISSUE_TEMPLATE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 🚨 Expired LaunchDarkly Feature Flag: {{flagName}}
2+
3+
## Flag Details
4+
- **Flag Name**: `{{flagName}}`
5+
- **Flag Key**: `{{flagKey}}`
6+
- **Expired Date**: {{expiryDate}}
7+
- **Days Overdue**: {{daysOverdue}} days
8+
9+
## Action Required
10+
This feature flag has expired and should be reviewed for cleanup.
11+
12+
### Cleanup Steps
13+
- [ ] Review flag usage in codebase
14+
- [ ] Verify flag is no longer needed
15+
- [ ] Remove flag references from code
16+
- [ ] Archive flag in LaunchDarkly
17+
- [ ] Close this issue
18+
19+
### Context
20+
This issue was automatically created by the [LaunchDarkly Feature Flag Expiry Audit Action](https://github.com/{{repoOwner}}/{{repoName}}/actions).
21+
22+
**Project**: {{projectKey}}
23+
**Audit Date**: {{auditDate}}
24+
25+
---
26+
⚠️ **Important**: Please review this flag's usage before deletion to avoid breaking functionality.

0 commit comments

Comments
 (0)