From d3a73857f97a3a218a8fd47865fe91e7db158f0c Mon Sep 17 00:00:00 2001 From: Katie McFaul Date: Thu, 17 Oct 2024 16:32:11 -0400 Subject: [PATCH] feat(workflow): update workflow to add date field --- .github/workflows/extensions.yml | 120 +++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 22 deletions(-) diff --git a/.github/workflows/extensions.yml b/.github/workflows/extensions.yml index 2021328..d011bc8 100644 --- a/.github/workflows/extensions.yml +++ b/.github/workflows/extensions.yml @@ -1,4 +1,3 @@ - name: Add new issues to PatternFly Extensions project on: @@ -18,24 +17,101 @@ jobs: label-issue: runs-on: ubuntu-latest steps: - - name: Team Membership Checker - # You may pin to the exact commit or the version. - # uses: TheModdingInquisition/actions-team-membership@a69636a92bc927f32c3910baac06bacc949c984c - uses: TheModdingInquisition/actions-team-membership@v1.0 - with: - # Repository token. GitHub Action token is used by default(recommended). But you can also use the other token(e.g. personal access token). - token: ${{ secrets.GH_READ_ORG_TOKEN }} - # The team to check for. - team: 'frequent-flyers' - # The organization of the team to check for. Defaults to the context organization. - organization: 'patternfly' - # If the action should exit if the user is not part of the team. - exit: true - - - name: Add label if user is a team member - run: | - curl -X POST \ - -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ - -H "Accept: application/vnd.github.v3+json" \ - https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \ - -d '{"labels":["PF Team"]}' + - name: Team Membership Checker + # You may pin to the exact commit or the version. + # uses: TheModdingInquisition/actions-team-membership@a69636a92bc927f32c3910baac06bacc949c984c + uses: TheModdingInquisition/actions-team-membership@v1.0 + with: + # Repository token. GitHub Action token is used by default(recommended). But you can also use the other token(e.g. personal access token). + token: ${{ secrets.GH_READ_ORG_TOKEN }} + # The team to check for. + team: 'frequent-flyers' + # The organization of the team to check for. Defaults to the context organization. + organization: 'patternfly' + # If the action should exit if the user is not part of the team. + exit: true + + - name: Add label if user is a team member + run: | + curl -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels \ + -d '{"labels":["PF Team"]}' + track-issue: + runs-on: ubuntu-latest + steps: + - name: Get project data + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ORGANIZATION: patternfly + PROJECT_NUMBER: 7 + run: | + gh api graphql -f query=' + query($org: String!, $number: Int!) { + organization(login: $org) { + projectV2(number: $number) { + id + fields(first:20) { + nodes { + ... on ProjectV2Field { + id + name + } + ... on ProjectV2SingleSelectField { + id + name + options { + id + name + } + } + } + } + } + } + }' -f org=$ORGANIZATION -F number=$PROJECT_NUMBER > project_data.json + + echo 'PROJECT_ID='$(jq '.data.organization.projectV2.id' project_data.json) >> $GITHUB_ENV + echo 'DATE_FIELD_ID='$(jq '.data.organization.projectV2.fields.nodes[] | select(.name== "Date added") | .id' project_data.json) >> $GITHUB_ENV + + - name: Add issue to project & get project issue id + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE_ID: ${{ github.event.issue.number }} + run: | + item_id="$(gh api graphql -f query=' + mutation($project: ID!, $issue: ID!) { + addProjectV2ItmById(input: { projectId: $project, contentId: $issue }) { + item { id } + } + } + ' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectV2ItemById.item.id')" + + echo 'ITEM_ID='$item_id >> $GITHUB_ENV + + - name: Get date + run: echo "DATE=$(date +"%Y-%m-%d")" >> $GITHUB_ENV + + - name: Set project fields + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api graphql -f query=' + mutation( + $project: ID!, + $item: ID!, + $date_field: ID!, + $date_value: Date! + ) { + set_date_added: updateProjectV2ItemFieldValue(input: { + projectId: $project, + itemId: $item, + fieldId: $date_field, + value: { + date: $date_value + } + }) { + projectV2Item { id } + } + }' -f project=$PROJECT_ID -f item=$ITEM_ID -f date_field=$DATE_FIELD_ID -f date_value=$DATE --silent