Skip to content

Commit

Permalink
ci(actions): add action to remove issues from design projects (#11249)
Browse files Browse the repository at this point in the history
**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
DitwanP authored Jan 16, 2025
1 parent e76f87a commit da08702
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/scripts/removeIssuesFromDesignProjects.js
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);
}
27 changes: 27 additions & 0 deletions .github/workflows/remove-issue-from-design-projects.yml
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

0 comments on commit da08702

Please sign in to comment.