Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci(actions): add action to archive issues in design projects #11249

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/scripts/archiveIssuesInDesignProjects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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;
const labelName = process.env.LABEL_NAME;

// 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) {
if (labelName === "ready for dev") {
const archiveQuery = `mutation { archiveProjectV2Item(input: {projectId: "${projectItem.project.id}", itemId: "${projectItem.id}"}) { clientMutationId } }`;
runQuery(archiveQuery);
createComment(
`The design work for this issue has been completed and it is now ready for development.\n\nThe issue has been archived in the [${projectItem.project.title}](${projectItem.project.url}/archive) project.`,
);
console.log("Issue archived in project.");
} else {
console.log("No action taken, label added was not 'ready for dev'.");
}
} 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/archive-design-issues-in-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:
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 }}
LABEL_NAME: ${{ github.event.label.name }}
run: node .github/scripts/archiveIssuesInDesignProjects.js
Loading