Skip to content

Commit

Permalink
Update issue_triage.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayank77maruti authored Dec 19, 2024
1 parent 787da44 commit 23465e8
Showing 1 changed file with 53 additions and 43 deletions.
96 changes: 53 additions & 43 deletions .github/workflows/issue_triage.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,64 @@
name: Fetch Issue Number and Project Items
name: Issue Triage and Assignment

on:
push:
branches:
- main
workflow_dispatch:
issues:
types: [labeled, assigned]
project_card:
types: [created, moved, converted] # Trigger when an issue is added to/moved between projects

permissions:
issues: write # Required to post comments on issues
contents: read # Allows read access to repo content, but not specifically required for projects

jobs:
fetch-issue-data:
verify-and-move-issue:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Fetch issues from repository
id: fetch_issues
run: |
response=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/oppia/oppia-android/issues?state=open")
issue_number=$(echo "$response" | jq '.[0].number')
echo "Issue number: $issue_number"
echo "ISSUE_NUMBER=$issue_number" >> $GITHUB_ENV
- name: Set up GraphQL query with dynamic issue number
run: |
echo "GRAPHQL_QUERY=$(cat <<EOF
{
repository(owner: \"oppia\", name: \"oppia-android\") {
issue(number: ${{ env.ISSUE_NUMBER }}) {
number
projectItems(first: 100) {
nodes {
project {
title
- name: Check Project Assignments
id: check-projects
uses: actions/github-script@v6
with:
script: |
const query = `
query($owner: String!, $repo: String!, $issueNumber: Int!) {
repository(owner: $owner, name: $repo) {
issue(number: $issueNumber) {
number
projectItems(first: 100) {
nodes {
project {
title
}
}
}
}
}
}
}
}
}
EOF
)" >> $GITHUB_ENV
`;
const variables = {
owner: context.repo.owner,
repo: context.repo.repo,
issueNumber: context.issue.number
};
- name: Run GraphQL query using GitHub API
uses: octokit/graphql-action@v3
with:
query: ${{ env.GRAPHQL_QUERY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
try {
const result = await github.graphql(query, variables);
const projects = result.repository.issue.projectItems.nodes;
- name: Output results
run: |
echo "Fetched issue number: ${{ env.ISSUE_NUMBER }} and project items"
if (projects.length !== 1) {
const message = \`This issue must belong to exactly one project. Currently assigned to ${projects.length} project(s).\`;
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
});
core.setOutput('projectValid', false);
} else {
core.setOutput('projectValid', true);
core.setOutput('projectTitle', projects[0].project.title);
}
} catch (error) {
core.setFailed('Failed to fetch issue data or check project assignments');
}

0 comments on commit 23465e8

Please sign in to comment.