all-contributors-import:update #30
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: Subscribe | |
"on": | |
repository_dispatch: | |
types: | |
- "all-contributors-import:update" | |
jobs: | |
subscribe: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/upload-artifact@v3 | |
with: | |
name: event.json | |
path: ${{ github.event_path }} | |
- uses: gr2m/github-app-token-action@v1 | |
id: app-token | |
with: | |
app_id: ${{ vars.ALL_CONTRIBUTORS_IMPORT_APP_ID }} | |
private_key: ${{ secrets.ALL_CONTRIBUTORS_IMPORT_APP_PRIVATE_KEY }} | |
- uses: actions/github-script@v6 | |
env: | |
START_SEQ: ${{ github.event.client_payload.startSeq }} | |
END_SEQ: ${{ github.event.client_payload.endSeq }} | |
with: | |
github-token: ${{ steps.app-token.outputs.token }} | |
script: | | |
// download the latest version of endorsements.csv | |
const response = await fetch( | |
"https://raw.githubusercontent.com/gr2m/all-contributors-import/main/data/endorsements.csv" | |
); | |
const text = await response.text(); | |
// find all new endorsements | |
const [firstLine, ...lines] = text.split("\n"); | |
const newLines = lines.filter((line) => { | |
const [seq] = line.split(","); | |
return Number(seq) >= process.env.START_SEQ; | |
}); | |
// create a markdown table | |
const headers = firstLine.split(","); | |
const table = `|${headers.join("|")}| | |
|${headers.map(() => "-").join("|")}| | |
${newLines.map((line) => `|${line.split(",").join("|")}|`).join("\n")} | |
`; | |
// create a new issue | |
github.request("POST /repos/{owner}/{repo}/issues", { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: `🤖📯 ${ | |
process.env.END_SEQ - process.env.START_SEQ | |
} new endorsements have been added`, | |
body: table, | |
}); |