|
1 | | -# Template |
| 1 | +# Auto Update Project Fields on Issue Close |
| 2 | + |
| 3 | +This GitHub Action automatically updates custom fields of items in an **Organization Project** (GitHub Projects v2) when an issue is closed. It is designed for organizations using GitHub Projects (v2) to track issues and automate field updates based on configurable rules. |
| 4 | + |
| 5 | +## Features |
| 6 | +- **Automated Field Updates:** Updates custom fields for project items when issues are closed. |
| 7 | +- **Supports Multiple Field Types:** Number, SingleSelect, Date, and Text fields are supported. |
| 8 | +- **Configurable:** Supports custom field configuration via a JSON file. |
| 9 | +- **Secure:** Requires a GitHub token for authentication. |
| 10 | + |
| 11 | +## Usage |
| 12 | +Add the following to your workflow YAML: |
| 13 | + |
| 14 | +```yaml |
| 15 | +on: |
| 16 | + issues: |
| 17 | + types: [closed] |
| 18 | + |
| 19 | +jobs: |
| 20 | + update-project-fields: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v3 |
| 25 | + - name: Update Project Fields |
| 26 | + uses: DevOpsVisions/project-fields-updater@main |
| 27 | + with: |
| 28 | + org: "your-org" |
| 29 | + project_number: "your-project-number" |
| 30 | + owner: "your-repo-owner" |
| 31 | + repo: "your-repo-name" |
| 32 | + issue_number: "${{ github.event.issue.number }}" |
| 33 | + config_path: "fields-config.json" # Optional, defaults to fields-config.json |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | +``` |
| 37 | +
|
| 38 | +## Inputs |
| 39 | +| Name | Description | Required | Default | |
| 40 | +|----------------|--------------------------------------|----------|----------------------| |
| 41 | +| org | The organization name | Yes | - | |
| 42 | +| project_number | The project number | Yes | - | |
| 43 | +| owner | The repository owner | Yes | - | |
| 44 | +| repo | The repository name | Yes | - | |
| 45 | +| issue_number | The issue number | Yes | - | |
| 46 | +| config_path | Path to the fields-config.json file | No | fields-config.json | |
| 47 | +
|
| 48 | +## Field Configuration |
| 49 | +Supported field types: **Number**, **SingleSelect**, **Date**, and **Text**. |
| 50 | +
|
| 51 | +Create a `fields-config.json` file in your repository to specify which fields to update and how. Example: |
| 52 | + |
| 53 | +```json |
| 54 | +[ |
| 55 | + { |
| 56 | + "field_name": "Week", |
| 57 | + "field_type": "number", |
| 58 | + "field_value": "30" |
| 59 | + }, |
| 60 | + { |
| 61 | + "field_name": "Month", |
| 62 | + "field_type": "singleSelect", |
| 63 | + "field_value": "Jul" |
| 64 | + }, |
| 65 | + { |
| 66 | + "field_name": "Date", |
| 67 | + "field_type": "date", |
| 68 | + "field_value": "2025-07-22" |
| 69 | + }, |
| 70 | + { |
| 71 | + "field_name": "Reason", |
| 72 | + "field_type": "text", |
| 73 | + "field_value": "Reason for the change" |
| 74 | + } |
| 75 | +] |
| 76 | +``` |
| 77 | +### Organization Default Use Case |
| 78 | + |
| 79 | +In our organization, we initially created this action to automatically update the following fields when closing an issue: |
| 80 | +- **Week**: with the current week number |
| 81 | +- **Month**: with the current month (e.g., "Jul") |
| 82 | +- **Date**: with the current date |
| 83 | + |
| 84 | +If this matches your use case, set the `field_value` to `auto` for these fields in your config, and the action will update them with the current values automatically. |
| 85 | + |
| 86 | +Example (`fields-config.json`): |
| 87 | + |
| 88 | +```json |
| 89 | +[ |
| 90 | + { |
| 91 | + "field_name": "Week", |
| 92 | + "field_type": "number", |
| 93 | + "field_value": "auto" |
| 94 | + }, |
| 95 | + { |
| 96 | + "field_name": "Month", |
| 97 | + "field_type": "singleSelect", |
| 98 | + "field_value": "auto" |
| 99 | + }, |
| 100 | + { |
| 101 | + "field_name": "Date", |
| 102 | + "field_type": "date", |
| 103 | + "field_value": "auto" |
| 104 | + } |
| 105 | +] |
| 106 | +``` |
| 107 | + |
| 108 | +## How It Works |
| 109 | +1. **Install GitHub CLI:** The action installs the GitHub CLI (`gh`) for API access. |
| 110 | +2. **Find Project Item:** Locates the project item for the closed issue. |
| 111 | +3. **Update Fields:** Updates the specified fields using the configuration file. |
| 112 | + |
| 113 | +## Requirements |
| 114 | +- Organization Projects (GitHub Projects v2) |
| 115 | +- GitHub CLI (`gh`) |
| 116 | +- `GITHUB_TOKEN` with the following permissions: |
| 117 | + - **Organization permissions:** Read and Write access to issue fields and organization projects |
| 118 | + - **Repository permissions:** Read access to code, issues, and metadata |
| 119 | + |
| 120 | +## Scripts |
| 121 | +Scripts are located in `src/scripts/`: |
| 122 | +- `entrypoint.sh`: Main entry point |
| 123 | +- `get-project-info.sh`: Fetches project info |
| 124 | +- `find-item-id.sh`: Finds the project item ID |
| 125 | +- `update-fields.sh`: Updates custom fields |
| 126 | + |
| 127 | +## License |
| 128 | +MIT |
| 129 | + |
| 130 | +## Author |
| 131 | +DevOpsVisions |
2 | 132 |
|
3 | 133 |
|
4 | 134 |
|
0 commit comments