-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(actions): add action to remove issues from design projects (#11249)
**Related Issue:** #10327 ## Summary Action that will remove issues from respective projects after design team has marked them with the `ready for dev` label.
- Loading branch information
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { execSync } = require("child_process"); | ||
|
||
// Environment variables from the GitHub Action | ||
const owner = process.env.OWNER; | ||
const repo = process.env.REPO; | ||
const issueNumber = process.env.ISSUE_NUMBER; | ||
|
||
// Function to execute a GitHub GraphQL command | ||
function runQuery(query) { | ||
const command = `gh api graphql -f query='${query}' -F owner="${owner}" -F repo="${repo}" -F issueNumber=${issueNumber}`; | ||
return execSync(command, { encoding: "utf-8" }); | ||
} | ||
|
||
// Function to create a comment | ||
async function createComment(body) { | ||
const command = `gh issue comment ${issueNumber} --body "${body}"`; | ||
return execSync(command, { encoding: "utf-8" }); | ||
} | ||
|
||
// GraphQL query to find the project associated with the issue | ||
const query = ` | ||
query($owner: String!, $repo: String!, $issueNumber: Int!) { | ||
repository(owner: $owner, name: $repo) { | ||
id | ||
nameWithOwner | ||
description | ||
issue(number: $issueNumber) { | ||
id | ||
title | ||
projectItems(first: 1) { | ||
nodes { | ||
id | ||
project { | ||
id | ||
title | ||
url | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
try { | ||
const result = runQuery(query); | ||
const parsedResult = JSON.parse(result); | ||
const projectItem = parsedResult.data.repository.issue.projectItems.nodes[0]; | ||
console.log("Project Item:", projectItem); | ||
|
||
if (projectItem) { | ||
const deleteQuery = `mutation { deleteProjectV2Item(input: {projectId: "${projectItem.project.id}", itemId: "${projectItem.id}"}) { clientMutationId } }`; | ||
runQuery(deleteQuery); | ||
createComment( | ||
`The issue has been removed from the [${projectItem.project.title}](${projectItem.project.url}) project.`, | ||
); | ||
console.log("Issue removed from project."); | ||
} else { | ||
console.log("No associated project found for this issue."); | ||
} | ||
} catch (error) { | ||
console.error("Error:", error.message); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Archive Issue in Project | ||
|
||
on: | ||
issues: | ||
types: [labeled] | ||
|
||
jobs: | ||
process-labeled-issue: | ||
if: github.event.label.name == 'ready for dev' | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: package.json | ||
|
||
- name: Archive Issue | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }} | ||
OWNER: ${{ github.repository_owner }} | ||
REPO: ${{ github.event.repository.name }} | ||
ISSUE_NUMBER: ${{ github.event.issue.number }} | ||
run: node .github/scripts/removeIssuesFromDesignProjects.js |