Data Download test #5
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: Respond to Cache Data Command | |
on: | |
issue_comment: | |
types: [created] | |
jobs: | |
respond-to-cache-command: | |
runs-on: ubuntu-latest | |
if: contains(github.event.comment.body, '@roboneuro cache data for https://github.com/') | |
steps: | |
- name: Check for Cache Data Command Pattern | |
id: check-pattern | |
run: | | |
COMMENT_BODY="${{ github.event.comment.body }}" | |
if [[ "$COMMENT_BODY" =~ @roboneuro\ cache\ data\ for\ (https://github.com/[^ ]+) ]]; then | |
REPO_URL="${BASH_REMATCH[1]}" | |
echo "repository_url=$REPO_URL" >> $GITHUB_ENV | |
else | |
echo "No valid cache data command found." | |
exit 1 | |
fi | |
- name: Check if Commenter is in Editors Team | |
id: check-authorization | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const commenter = context.payload.comment.user.login; | |
const org = "neurolibre"; | |
const team_slug = "editors"; | |
const { data: members } = await github.rest.teams.listMembersInOrg({ | |
org, | |
team_slug, | |
}); | |
const isAuthorized = members.some(member => member.login === commenter); | |
core.setOutput("authorized", isAuthorized); | |
- name: Comment with Download Message | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.BOT_TOKEN }} | |
script: | | |
const repoUrl = process.env.repository_url; | |
const repoOwner = repoUrl.replace('https://github.com/', ''); | |
const isAuthorized = "${{ steps.check-authorization.outputs.authorized }}" === "true"; | |
const message = isAuthorized ? `Downloading data for ${repoOwner}` : "You are not authorized to perform this action."; | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: message | |
}); |