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
7471e37
commit 787da44
Showing
1 changed file
with
43 additions
and
45 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,56 +1,54 @@ | ||
name: Issue Triage and Assignment | ||
name: Fetch Issue Number and Project Items | ||
|
||
on: | ||
issues: | ||
types: [labeled, assigned] | ||
|
||
permissions: write-all | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
|
||
jobs: | ||
verify-and-move-issue: | ||
fetch-issue-data: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- 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 | ||
} | ||
} | ||
} | ||
- 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 | ||
} | ||
} | ||
} | ||
`; | ||
const variables = { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issueNumber: context.issue.number | ||
}; | ||
} | ||
} | ||
} | ||
EOF | ||
)" >> $GITHUB_ENV | ||
const result = await github.graphql(query, variables); | ||
const projects = result.repository.issue.projectItems.nodes; | ||
- name: Run GraphQL query using GitHub API | ||
uses: octokit/graphql-action@v3 | ||
with: | ||
query: ${{ env.GRAPHQL_QUERY }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
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); | ||
} | ||
- name: Output results | ||
run: | | ||
echo "Fetched issue number: ${{ env.ISSUE_NUMBER }} and project items" |