-
Notifications
You must be signed in to change notification settings - Fork 1
102 lines (86 loc) · 3.2 KB
/
getGitHubRepos.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Get GitHub Repos
on:
# cronjob trigger
schedule:
- cron: "0 0 * * *"
# manual trigger
workflow_dispatch:
jobs:
get-github-repos:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20.x'
- run: npm install @octokit/core
- name: Get Repository Data
uses: actions/github-script@v7
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
script: |
const { Octokit, App } = require('@octokit/core')
const octokit = new Octokit({
auth: `bearer ${process.env.GITHUB_TOKEN}`
})
var fs = require('fs');
const query = `query($org: String!) {
organization(login: $org) {
repositories(first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
nodes {
name
description
homepageUrl
repositoryTopics(first: 5) {
nodes {
topic {
name
}
}
}
}
}
}
}`;
const variables = {
org: 'ibm-client-engineering',
};
const repoData = await github.graphql(query, variables)
const getProps = require('./.github/workflows/getProps.js')
const finalRepoData = await getProps({repoData, octokit})
fs.writeFileSync('repoData.json', JSON.stringify(finalRepoData, null, 2));
- name: Commit and push JSON file
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v3
continue-on-error: true
with:
token: ${{ secrets.GITHUB_TOKEN }}
add-paths: |
repoData.json
commit-message: Add repository data JSON file
- name: Enable Pull Request Automerge
if: ${{steps.cpr.outcome == 'success' && steps.cpr.outputs.pull-request-operation == 'created'}}
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: squash
- name: Generate a token
id: generate-token
if: ${{steps.cpr.outcome == 'success' && steps.cpr.outputs.pull-request-operation == 'created'}}
uses: actions/create-github-app-token@v1
with:
app-id: ${{ vars.SOLUTIONS_HUB_APP_ID }}
private-key: ${{ secrets.SOLUTIONS_HUB_APP_KEY }}
- name: Auto approve
if: ${{steps.cpr.outcome == 'success' && steps.cpr.outputs.pull-request-operation == 'created'}}
run: gh pr review --approve "${{ steps.cpr.outputs.pull-request-number }}"
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}