Remove Governed Labels #42
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
name: Remove Governed Labels | |
on: | |
discussion: | |
types: [created] | |
jobs: | |
check_labels: | |
name: Check labels | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check if employee | |
id: check_employee | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.READ_GITHUB_ORG_MEMBERS_TOKEN }} | |
result-encoding: string | |
script: | | |
console.log(context.payload); | |
try { | |
const response = await github.rest.orgs.checkMembershipForUser({ | |
org: `github`, | |
username: context.payload.sender.login | |
}); | |
if (response.status === 204) { | |
return 'true'; | |
} else { | |
return 'false'; | |
} | |
} catch (error) { | |
console.log(error); | |
return 'false'; | |
} | |
- name: Fetch label id | |
id: fetch_label_id | |
if: ${{ steps.check_employee.outputs.result == 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
TOPIC: 'more information needed' | |
run: | | |
gh api graphql -F owner=$OWNER -F name=$REPO -F topic="$TOPIC" -f query=' | |
query($owner: String!, $name: String!, $topic: String) { | |
repository(owner: $owner, name: $name){ | |
labels(first: 1, query: $topic) { | |
edges { | |
node { | |
id | |
name | |
} | |
} | |
} | |
} | |
}' > repository_label_data.json | |
echo 'LABEL_ID='$(jq '.data.repository.labels.edges[].node | .id ' repository_label_data.json) >> $GITHUB_ENV | |
- name: Fetch discussion ID | |
id: fetch_discussion_id | |
if: ${{ steps.check_employee.outputs.result == 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
TOPIC: 'more information needed' | |
run: | | |
gh api graphql -F owner=$OWNER -F name=$REPO -f query=' | |
query($owner: String!, $name: String!) { | |
repository(owner: $owner, name: $name) { | |
discussion(number: ${{ github.event.discussion.number }}) { | |
id | |
} | |
} | |
}' > discussion_data.json | |
echo 'DISCUSSION_ID='$(jq '.data.repository.discussion.id' discussion_data.json) >> $GITHUB_ENV | |
- name: Unlabel the discussion | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
TOPIC: 'more information needed' | |
run: | | |
gh api graphql -f query=' | |
mutation($labelableId: ID!, $labelIds: [ID!]!) { | |
removeLabelsFromLabelable(input: {labelableId: $labelableId, labelIds: $labelIds}) { | |
labelable { | |
labels(first: 10) { | |
edges { | |
node { | |
id | |
name | |
} | |
} | |
} | |
} | |
} | |
}' -f labelableId=$DISCUSSION_ID -f labelIds=$LABEL_ID |