From bc4b3b0c4851751255b20a39e05716713ce50aa1 Mon Sep 17 00:00:00 2001 From: Belle P Date: Mon, 18 Nov 2024 09:26:01 -0800 Subject: [PATCH] Added github action workflows to test --- .../workflows/add-issue-to-second-project.yml | 33 ++++++++ .github/workflows/assign-user-from-label.yml | 16 ++++ .../workflows/link-issue-as-dependency.yml | 16 ++++ .github/workflows/set-issue-label.yml | 16 ++++ .../workflows/sync-status-across-projects.yml | 76 +++++++++++++++++++ .github/workflows/update-issue-status.yml | 16 ++++ 6 files changed, 173 insertions(+) create mode 100644 .github/workflows/add-issue-to-second-project.yml create mode 100644 .github/workflows/assign-user-from-label.yml create mode 100644 .github/workflows/link-issue-as-dependency.yml create mode 100644 .github/workflows/set-issue-label.yml create mode 100644 .github/workflows/sync-status-across-projects.yml create mode 100644 .github/workflows/update-issue-status.yml diff --git a/.github/workflows/add-issue-to-second-project.yml b/.github/workflows/add-issue-to-second-project.yml new file mode 100644 index 0000000..4c1f6af --- /dev/null +++ b/.github/workflows/add-issue-to-second-project.yml @@ -0,0 +1,33 @@ +name: Add Issue to Second Project + +on: + issues: + types: [opened] + +jobs: + add-issue-to-project: + runs-on: ubuntu-latest + steps: + - name: Add Issue to Secondary Project + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const projectId = 'YOUR_SECOND_PROJECT_ID'; // Replace with your target project ID + + const issue = context.payload.issue; + + const addProjectItem = await github.graphql(` + mutation($projectId: ID!, $contentId: ID!) { + addProjectV2ItemById(input: {projectId: $projectId, contentId: $contentId}) { + item { + id + } + } + } + `, { + projectId: projectId, + contentId: issue.node_id + }); + + console.log(`Issue #${issue.number} added to project with item ID: ${addProjectItem.addProjectV2ItemById.item.id}`); \ No newline at end of file diff --git a/.github/workflows/assign-user-from-label.yml b/.github/workflows/assign-user-from-label.yml new file mode 100644 index 0000000..3593dd4 --- /dev/null +++ b/.github/workflows/assign-user-from-label.yml @@ -0,0 +1,16 @@ +name: Auto-label Issues + +on: + issues: + types: [opened, edited] + +jobs: + label-issue: + runs-on: ubuntu-latest + steps: + - name: Add Bug Label + if: contains(github.event.issue.title, 'bug') + uses: actions-ecosystem/action-add-labels@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + labels: "bug" \ No newline at end of file diff --git a/.github/workflows/link-issue-as-dependency.yml b/.github/workflows/link-issue-as-dependency.yml new file mode 100644 index 0000000..ed52d06 --- /dev/null +++ b/.github/workflows/link-issue-as-dependency.yml @@ -0,0 +1,16 @@ +name: Track Dependencies + +on: + issues: + types: [opened, edited] + +jobs: + add-dependency: + runs-on: ubuntu-latest + steps: + - name: Add Dependency Label + if: contains(github.event.issue.body, '#dependent-on') + uses: actions-ecosystem/action-add-labels@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + labels: "dependency" \ No newline at end of file diff --git a/.github/workflows/set-issue-label.yml b/.github/workflows/set-issue-label.yml new file mode 100644 index 0000000..3593dd4 --- /dev/null +++ b/.github/workflows/set-issue-label.yml @@ -0,0 +1,16 @@ +name: Auto-label Issues + +on: + issues: + types: [opened, edited] + +jobs: + label-issue: + runs-on: ubuntu-latest + steps: + - name: Add Bug Label + if: contains(github.event.issue.title, 'bug') + uses: actions-ecosystem/action-add-labels@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + labels: "bug" \ No newline at end of file diff --git a/.github/workflows/sync-status-across-projects.yml b/.github/workflows/sync-status-across-projects.yml new file mode 100644 index 0000000..191261a --- /dev/null +++ b/.github/workflows/sync-status-across-projects.yml @@ -0,0 +1,76 @@ +name: Sync Status Across Projects + +on: + issues: + types: [edited, labeled, unlabeled, closed, reopened] + +jobs: + sync-status: + runs-on: ubuntu-latest + steps: + - name: Sync Status Field + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const sourceProjectId = 'YOUR_SOURCE_PROJECT_ID'; // Replace with the source project ID + const targetProjectId = 'YOUR_TARGET_PROJECT_ID'; // Replace with the target project ID + const statusFieldId = 'YOUR_STATUS_FIELD_ID'; // Replace with the status field ID for both projects + + // Fetch the current issue status from the source project + const issueNodeId = context.payload.issue.node_id; + + // Fetch the status field value in the source project + const { resource } = await github.graphql(` + query($projectId: ID!, $issueId: ID!) { + node(id: $issueId) { + ... on Issue { + projectItems(first: 10) { + nodes { + fieldValues(first: 10) { + nodes { + projectField { + id + } + value + } + } + } + } + } + } + } + `, { + projectId: sourceProjectId, + issueId: issueNodeId + }); + + // Extract the current status from the source project + const currentStatus = resource.node.projectItems.nodes.find(item => item.projectField.id === statusFieldId)?.value; + + if (!currentStatus) { + console.log("No status field found or status has not changed."); + return; + } + + // Update the status in the target project + await github.graphql(` + mutation($projectId: ID!, $contentId: ID!, $status: String!) { + updateProjectV2ItemFieldValue(input: { + projectId: $projectId, + itemId: $contentId, + fieldId: "${statusFieldId}", + value: $status + }) { + projectV2Item { + id + } + } + } + `, { + projectId: targetProjectId, + contentId: issueNodeId, + status: currentStatus + }); + + console.log(`Status synced successfully to target project for issue ID: ${issueNodeId}`); \ No newline at end of file diff --git a/.github/workflows/update-issue-status.yml b/.github/workflows/update-issue-status.yml new file mode 100644 index 0000000..c871500 --- /dev/null +++ b/.github/workflows/update-issue-status.yml @@ -0,0 +1,16 @@ +name: Update Issue Status + +on: + pull_request: + types: [closed] + +jobs: + update-status: + runs-on: ubuntu-latest + steps: + - name: Update Issue Status to "Done" + uses: actions-ecosystem/action-update-comment@v1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + issue_number: ${{ github.event.issue.number }} + comment: "Status: Done" \ No newline at end of file