forked from oppia/oppia-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
787da44
commit 23465e8
Showing
1 changed file
with
53 additions
and
43 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 |
---|---|---|
@@ -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'); | ||
} |