Download data for EEG StudyTemplate #25
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.DATA_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 | |
id: comment-download | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.DATA_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 ? `Pinging roboneuro to download the data for ${repoOwner}` : "You are not authorized to perform this action."; | |
core.setOutput("proceed", isAuthorized); | |
await github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: message | |
}); | |
- name: Debug Cache Data Variables | |
if: steps.comment-download.outputs.proceed == 'true' | |
run: | | |
echo "Debugging Cache Data Variables:" | |
echo "id: ${{ github.event.issue.number }}" | |
echo "repository_url: ${{ env.repository_url }}" | |
echo "external_repo: ${{ github.repository }}" | |
- name: Cache Data | |
if: steps.comment-download.outputs.proceed == 'true' | |
run: | | |
curl -X POST https://preview.neurolibre.org/api/data/cache \ | |
-u "${{ secrets.PREVIEW_API_USERNAME }}:${{ secrets.PREVIEW_API_PASSWORD }}" \ | |
-H "Content-Type: application/json" \ | |
-d '{ | |
"repository_url": "'${{ env.repository_url }}'", | |
"id": "'${{ github.event.issue.number }}'", | |
"external_repo": "'${{ github.repository }}'" | |
}' |