Create on-create-notes.yml #4
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: 'created discussion action' | |
on: | |
discussion: | |
types: [created] | |
permissions: | |
contents: read | |
discussions: write | |
jobs: | |
action: | |
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: | | |
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 discussion ID | |
id: fetch_discussion_id | |
if: ${{ steps.check_employee.outputs.result == 'true' && github.event.repository && github.event.discussion }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
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 Discussion | |
if: ${{ steps.check_employee.outputs.result == 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
OWNER: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
config-path: '.github/label-actions.yml' |