Sync Contributors Data #14
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 : Sync Contributors Data | |
on: | |
schedule: # Run sunday at midnight every week | |
- cron: '0 0 * * 0' | |
workflow_dispatch: | |
jobs: | |
sync-contributors-data: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Get Token | |
uses: actions/create-github-app-token@v1 | |
id: get_workflow_token | |
with: | |
app-id: ${{ vars.APP_ID }} | |
private-key: ${{ secrets.PRIVATE_KEY }} | |
- name: Fetch Contributors data | |
uses: actions/github-script@v7 | |
env: | |
ORGS: ${{ github.repository_owner }} | |
REPO: ${{ github.event.repository.name }} | |
with: | |
github-token: ${{ steps.get_workflow_token.outputs.token }} | |
script: | | |
const fs = require('fs'); | |
let data = await github.paginate(github.rest.repos.listContributors, { | |
owner: process.env.ORGS, | |
repo: process.env.REPO, | |
per_page: 100, | |
headers: { | |
"X-GitHub-Api-Version": "2022-11-28", | |
}, | |
}); | |
// Filter the data to get only the required fields | |
data = data.map(({ login, id, avatar_url, html_url }) => | |
({ login, id, avatar_url, html_url })); | |
// Store the data in a file | |
fs.writeFileSync('community.json', JSON.stringify(data, null, 2)); | |
- name: Commit changes | |
run: | | |
git config user.name "the-json-schema-bot[bot]" | |
git config user.email "the-json-schema-bot[bot]@users.noreply.github.com" | |
git add community.json | |
git diff --quiet && git diff --staged --quiet || (git commit -m "chore(community): update community.json") | |
- name: Create Pull Request | |
id: cpr | |
uses: peter-evans/create-pull-request@v6 | |
with: | |
token: ${{ steps.get_workflow_token.outputs.token }} | |
title: 'chore(community): update community.json' | |
body: 'This PR updates the community.json file with the latest contributors data.' | |
branch: 'update-contributors' | |
base: 'main' | |
author: 'the-json-schema-bot <the-json-schema-bot[bot]@users.noreply.github.com>' | |
branch-suffix: timestamp | |
labels: 'sync-contributors' | |
assignees: 'the-json-schema-bot' | |
draft: false | |
signoff: true | |
add-paths: 'community.json' | |
# Approving with github bot token because one cannot approve their own PRs | |
- name: Auto Approve | |
if: steps.cpr.outputs.pull-request-operation == 'created' | |
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}" | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Auto Merge PR | |
if: steps.cpr.outputs.pull-request-operation == 'created' | |
uses: peter-evans/enable-pull-request-automerge@v3 | |
with: | |
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} | |
merge-method: 'squash' | |
token: ${{ steps.get_workflow_token.outputs.token }} | |