]> git.kaiwu.me - nginx.git/commitdiff
GH: set new issues creation date master
authorAndrew Clayton <a.clayton@nginx.com>
Wed, 4 Mar 2026 18:46:34 +0000 (18:46 +0000)
committerAndrew Clayton <a.clayton@nginx.com>
Tue, 12 May 2026 18:42:40 +0000 (19:42 +0100)
When a new issue is created, set its 'Created at' date in the
corresponding project.

.github/workflows/set-creation-date.yaml [new file with mode: 0644]

diff --git a/.github/workflows/set-creation-date.yaml b/.github/workflows/set-creation-date.yaml
new file mode 100644 (file)
index 0000000..6dcbabc
--- /dev/null
@@ -0,0 +1,104 @@
+name: Set creation date
+
+on:
+  issues:
+    types:
+      - opened
+
+jobs:
+  set-date:
+    permissions:
+      id-token: write
+    if: ${{ github.repository == 'nginx/nginx' }}
+    runs-on: ubuntu-24.04
+
+    steps:
+      - name: Get secrets from Azure
+        uses: nginx/ci-self-hosted/.github/actions/get-from-vault@5c3e1f8b51f66a851fdba80f70e19cf966199730
+        with:
+          client-id: ${{ secrets.NGINX_OSS_CLIENT_ID }}
+          tenant-id: ${{ secrets.NGINX_OSS_TENANT_ID }}
+          vault-name: ${{ secrets.NGINX_OSS_VAULT_NAME }}
+          secret-names: "github-nginx-oss-app-project-client-id, github-nginx-oss-app-project-private-key"
+          env-names: "NGINX_OSS_PROJ_CLIENT_ID, NGINX_OSS_PROJ_PRIV_KEY"
+
+      - name: Generate token
+        id: generate-token
+        uses: actions/create-github-app-token@1b10c78c7865c340bc4f6099eb2f838309f1e8c3 # v3.1.1
+        with:
+          client-id: ${{ env.NGINX_OSS_PROJ_CLIENT_ID }}
+          private-key: ${{ env.NGINX_OSS_PROJ_PRIV_KEY }}
+
+      - name: Get project data
+        env:
+          GH_TOKEN: ${{ steps.generate-token.outputs.token }}
+          ORGANIZATION: nginx
+          PROJECT_NUMBER: 33
+        run: |
+          gh api graphql -f query='
+            query($org: String!, $number: Int!) {
+              organization(login: $org) {
+                projectV2(number: $number) {
+                  id
+                  fields(first:20) {
+                    nodes {
+                      ... on ProjectV2FieldCommon {
+                        id
+                        name
+                      }
+                    }
+                  }
+                }
+              }
+            }' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER >project_data.json
+
+          echo 'PROJECT_ID='$(jq -r '.data.organization.projectV2.id' project_data.json) >>$GITHUB_ENV
+          echo 'DATE_FIELD_ID='$(jq -r '.data.organization.projectV2.fields.nodes[] | select(.name == "Created at") | .id' project_data.json) >>$GITHUB_ENV
+
+      # Needed to get the item's Global ID
+      - name: Add item to project
+        env:
+          GH_TOKEN: ${{ steps.generate-token.outputs.token }}
+        run: |
+          NODE_ID=${{ github.event.issue.node_id }}
+
+          item_id="$(gh api graphql -f query='
+            mutation($project:ID!, $item:ID!) {
+              addProjectV2ItemById(
+                input: {
+                  projectId: $project, contentId: $item
+                }) {
+                  item {
+                    id
+                  }
+                }
+              }' -f project=$PROJECT_ID -f item=$NODE_ID --jq '.data.addProjectV2ItemById.item.id')"
+          echo 'ITEM_ID='$item_id >>$GITHUB_ENV
+
+      - name: Set item creation date
+        env:
+          GH_TOKEN: ${{ steps.generate-token.outputs.token }}
+        run: |
+          DATE=${{ github.event.issue.created_at }}
+
+          gh api graphql -f query='
+            mutation(
+              $project: ID!
+              $item: ID!
+              $date_field: ID!
+              $date: Date!
+            ) {
+              updateProjectV2ItemFieldValue(
+                input: {
+                  projectId: $project
+                  itemId: $item
+                  fieldId: $date_field
+                  value: {
+                    date: $date
+                  }
+                }) {
+                  projectV2Item {
+                    id
+                  }
+                }
+            }' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$DATE_FIELD_ID -f date=$DATE