Skip to content

Commit b37c5e2

Browse files
fix(action): fix and refactor the action set-date-closed-field-v1 (#327)
This pull request enhances the GitHub Action for setting a closed date field on issues by generalizing support for any date-type project field (not just `DateClosed`), improving documentation, and adding robust test coverage for new and existing utility functions. The action is now more flexible and maintainable, with clearer error messages and better user guidance. Tested in my test repo: - incorrect field - [failed](https://github.com/dequelabs/maksym-testing/actions/runs/23591546329) - issue not found - [failed](https://github.com/dequelabs/maksym-testing/actions/runs/23591574850) - issue is in another project - [success](https://github.com/dequelabs/maksym-testing/actions/runs/23591631450/job/68698046620) - set closed date - [success](https://github.com/dequelabs/maksym-testing/actions/runs/23591693601/job/68698254745) Closes: #319
1 parent 10cd739 commit b37c5e2

22 files changed

Lines changed: 1217 additions & 507 deletions

.github/actions/set-date-closed-field-v1/README.md

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
# Set DateClosed Field on Issue Close Action
1+
# Set Closed Date Field on Issue Close Action
22

3-
This action updates the `DateClosed` project field when an issue is closed as completed. If an issue is reopened and closed again, the `DateClosed` field will reflect the latest date that it was closed.
3+
This action updates a date project field (default: `DateClosed`) when an issue is closed as completed. If an issue is reopened and closed again, the field will reflect the latest date that it was closed.
44

55
## Quick Reference
66

7-
| Input | Description | Required | Default |
8-
| -------------------- | --------------------------------------------- | -------- | ------- |
9-
| `issue-number` | The issue number to check | Yes | - |
10-
| `issue-organization` | The organization where the issue is located | No | - |
11-
| `issue-repo` | The repository where the issue is located | No | - |
12-
| `project-number` | The project number where the issue is located | Yes | - |
7+
| Input | Description | Required | Default |
8+
| -------------------- | --------------------------------------------------------- | -------- | ------------ |
9+
| `token` | PAT with required permissions (see below) | Yes | - |
10+
| `issue-number` | The issue number to check | Yes | - |
11+
| `issue-organization` | The organization where the issue is located | No | - |
12+
| `issue-repo` | The repository where the issue is located | No | - |
13+
| `project-number` | The project number where the issue is located | Yes | - |
14+
| `date-field-name` | The name of the date field to update the issue close date | No | `DateClosed` |
1315

1416
**Requirements:**
1517

16-
- Custom `DateClosed` field (Date type) in your project
17-
- `GH_TOKEN` environment variable set to a Personal Access Token with `repo`, `read:org`, `write:org`, and `project` scopes
18+
- A custom date field (Date type) in your project (default name: `DateClosed`)
19+
- A Personal Access Token with `repo`, `read:org`, `write:org`, and `project` scopes
1820
- Issue must be added to the specified project board
1921

2022
## Setup
2123

22-
### 1. Create the DateClosed Custom Field
24+
### 1. Create the Date Custom Field
2325

2426
1. Navigate to your GitHub project board
2527
2. Click the "+" icon to add a new field
2628
3. Select "Custom field"
27-
4. Name the field `DateClosed` and set type to **Date**
29+
4. Name the field `DateClosed` (or your preferred name) and set type to **Date**
2830
5. Save the field
2931

3032
### 2. Create Personal Access Token
@@ -42,8 +44,6 @@ This action updates the `DateClosed` project field when an issue is closed as co
4244
3. Name: `PAT`, Value: your token
4345
4. Click "Add secret"
4446

45-
**Note**: The action now uses the `GH_TOKEN` environment variable instead of a token input parameter.
46-
4747
### 4. Find Your Project Number
4848

4949
**From GitHub UI:** Look at your project URL: `https://github.com/orgs/YOUR_ORG/projects/PROJECT_NUMBER`
@@ -57,7 +57,7 @@ gh project list --owner YOUR_ORG_OR_USERNAME
5757
## Usage
5858

5959
```yaml
60-
name: Set DateClosed Field on Issue Close
60+
name: Set Closed Date Field on Issue Close Action
6161

6262
on:
6363
issues:
@@ -71,16 +71,15 @@ jobs:
7171
- name: Checkout repository
7272
uses: actions/checkout@v4
7373

74-
- name: Set DateClosed Field on Issue Close
74+
- name: Set closed date field
7575
uses: dequelabs/axe-api-team-public/.github/actions/set-date-closed-field-v1@main
7676
with:
7777
issue-number: ${{ github.event.issue.number }}
7878
issue-organization: ${{ github.event.repository.owner.login }}
7979
issue-repo: ${{ github.event.repository.name }}
8080
project-number: '123' # Replace with your project number
81+
date-field-name: 'MyCustomDateField'
8182
token: ${{ secrets.PAT }}
82-
env:
83-
GH_TOKEN: ${{ secrets.PAT }}
8483
```
8584
8685
**Important:** The default `GITHUB_TOKEN` will not work for project operations. You must use a PAT as shown above.
@@ -90,37 +89,27 @@ jobs:
9089
1. **Issue Check** - Gets the issue details using the provided parameters
9190
2. **Closed Status Check** - Verifies the issue is closed and has a `closed_at` date
9291
3. **Project Item Lookup** - Finds the issue in the specified project board
93-
4. **DateClosed Field Update** - Updates the `DateClosed` field with the close date in YYYY-MM-DD format
92+
4. **Date Field Update** - Updates the specified date field (default: `DateClosed`) with the close date in YYYY-MM-DD format
9493
5. **Re-closing Support** - If an issue is reopened and closed again, the field reflects the latest close date
9594

9695
## Troubleshooting
9796

98-
### "Failed to get DateClosed field ID"
97+
### "Failed to get \<field name\> field ID"
9998

10099
**Causes:**
101100

102101
- Incorrect project number
103-
- DateClosed field doesn't exist in the project
102+
- The specified date field doesn't exist in the project
104103
- Token lacks project access
105104
- Project is in a different organization
106105

107106
**Solutions:**
108107

109108
1. Verify project number using: `gh project list --owner YOUR_ORG`
110-
2. Check if DateClosed field exists: `gh project field-list PROJECT_NUMBER --owner YOUR_ORG --format json`
109+
2. Check if the field exists: `gh project field-list PROJECT_NUMBER --owner YOUR_ORG --format json`
111110
3. Ensure PAT has all required scopes
112111
4. Confirm project organization matches your expectations
113112

114-
### "gh: To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable"
115-
116-
**Cause:** Missing or insufficient token permissions
117-
118-
**Solutions:**
119-
120-
1. Verify PAT includes all required scopes: `repo`, `read:org`, `write:org`, `project`
121-
2. Test token manually: `gh project field-list PROJECT_NUMBER --owner YOUR_ORG --format json`
122-
3. Ensure token has access to the specific project
123-
124113
### General Debugging Tips
125114

126115
- **Test project access:** Use GitHub CLI commands locally with your PAT to verify access

.github/actions/set-date-closed-field-v1/action.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: 'Set DateClosed Field on Issue Close'
2-
description: 'Update the DateClosed project field when an issue is closed as completed'
1+
name: 'Set Closed Date Field on Issue Action'
2+
description: 'Update a date project field (default: DateClosed) when an issue is closed as completed'
33
inputs:
44
token:
55
description: 'Token used for the GH CLI to close and move issue(s) to the correct column. See README for required permissions'
@@ -16,7 +16,11 @@ inputs:
1616
project-number:
1717
description: 'The project number where the issue is located (should be hardcoded in workflow)'
1818
required: true
19+
date-field-name:
20+
description: 'The name of the date field to update the issue close date'
21+
required: false
22+
default: 'DateClosed'
1923

2024
runs:
2125
using: 'node24'
22-
main: 'dist/index.js'
26+
main: 'dist/index.js'

.github/actions/set-date-closed-field-v1/dist/getFieldIdByName.d.ts

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/set-date-closed-field-v1/dist/getProjectBoardFieldList.d.ts

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/actions/set-date-closed-field-v1/dist/getProjectItemId.d.ts

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)