Skip to content

Commit a1a0dde

Browse files
committed
Configure the project via gitgitgadget-config.json
With this change, the GitGitGadget GitHub App truly learns about projects other than Git. Instead of hard-coding the respective project-dependent values, it now reads the project configuration from the `gitgitgadget-config.json` file, which adheres to the `IConfig` interface defined in https://github.com/gitgitgadget/gitgitgadget/blob/HEAD/lib/project-config.ts. One caveat: Since the App needs to know which `gitgitgadget-workflows` fork to target when triggering the GitHub workflows, an additional entry is required in the configuration that is _not_ defined in `IConfig`: workflowsRepo: { owner: "gitgitgadget-workflows", name: "gitgitgadget-workflows" } Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 58b1bb9 commit a1a0dde

File tree

3 files changed

+89
-15
lines changed

3 files changed

+89
-15
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"repo": {
3+
"name": "git",
4+
"owner": "gitgitgadget",
5+
"baseOwner": "git",
6+
"testOwner": "dscho",
7+
"owners": [
8+
"gitgitgadget",
9+
"git",
10+
"dscho"
11+
],
12+
"branches": [
13+
"maint",
14+
"seen"
15+
],
16+
"closingBranches": [
17+
"maint",
18+
"master"
19+
],
20+
"trackingBranches": [
21+
"maint",
22+
"seen",
23+
"master",
24+
"next"
25+
],
26+
"maintainerBranch": "gitster",
27+
"host": "github.com"
28+
},
29+
"mailrepo": {
30+
"name": "git",
31+
"owner": "gitgitgadget",
32+
"branch": "master",
33+
"host": "lore.kernel.org",
34+
"url": "https://lore.kernel.org/git/",
35+
"public_inbox_epoch": 1,
36+
"mirrorURL": "https://github.com/gitgitgadget/git-mailing-list-mirror",
37+
"mirrorRef": "refs/heads/lore-1",
38+
"descriptiveName": "lore.kernel/git"
39+
},
40+
"mail": {
41+
"author": "GitGitGadget",
42+
"sender": "GitGitGadget",
43+
"smtpUser": "[email protected]",
44+
"smtpHost": "smtp.gmail.com"
45+
},
46+
"app": {
47+
"appID": 12836,
48+
"installationID": 195971,
49+
"name": "gitgitgadget",
50+
"displayName": "GitGitGadget",
51+
"altname": "gitgitgadget-git"
52+
},
53+
"lint": {
54+
"maxCommitsIgnore": [
55+
"https://github.com/gitgitgadget/git/pull/923"
56+
],
57+
"maxCommits": 30
58+
},
59+
"user": {
60+
"allowUserAsLogin": false
61+
},
62+
"syncUpstreamBranches": [
63+
{
64+
"sourceRepo": "gitster/git",
65+
"targetRepo": "gitgitgadget/git",
66+
"sourceRefRegex": "^refs/heads/(maint-\\d|[a-z][a-z]/)"
67+
},
68+
{
69+
"sourceRepo": "j6t/git-gui",
70+
"targetRepo": "gitgitgadget/git",
71+
"targetRefNamespace": "git-gui/"
72+
}
73+
],
74+
"workflowsRepo": {
75+
"owner": "gitgitgadget-workflows",
76+
"name": "gitgitgadget-workflows"
77+
}
78+
}

GitGitGadget/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,18 @@ module.exports = async (context, req) => {
2626
}
2727

2828
try {
29-
/*
30-
* For various reasons, the GitGitGadget GitHub App can be installed
31-
* on any random repository. However, GitGitGadget only wants to support
32-
* the `gitgitgadget/git` and the `git/git` repository (with the
33-
* `dscho/git` one thrown in for debugging purposes).
34-
*/
35-
const orgs = ['gitgitgadget', 'git', 'dscho']
36-
const a = [context, undefined, 'gitgitgadget-workflows', 'gitgitgadget-workflows']
29+
const { readFileSync } = require('fs')
30+
const config = JSON.parse(readFileSync(`${__dirname}/gitgitgadget-config.json`))
31+
const orgs = config.repo.owners
32+
const a = [context, undefined, config.workflowsRepo.owner, config.workflowsRepo.name]
3733

3834
const eventType = context.req.headers['x-github-event'];
3935
context.log(`Got eventType: ${eventType}`);
4036
const repositoryOwner = req.body.repository.owner.login;
4137
if (!orgs.includes(repositoryOwner)) {
4238
context.res = {
4339
status: 403,
44-
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git'
40+
body: `Refusing to work on any repository outside of ${orgs.join(', ')}`,
4541
};
4642
} else if (eventType === 'pull_request') {
4743
if (req.body.action !== 'opened' && req.body.action !== 'synchronize') {
@@ -59,9 +55,9 @@ module.exports = async (context, req) => {
5955
body: `Ignored event type: ${eventType}`,
6056
};
6157
} else if (eventType === 'push') {
62-
if (req.body.repository.full_name ==='gitgitgadget/git-mailing-list-mirror') {
58+
if (config.mailrepo.mirrorURL === `https://github.com/${req.body.repository.full_name}`) {
6359
context.res = { body: `push(${req.body.ref} in ${req.body.repository.full_name}): ` }
64-
if (req.body.ref === 'refs/heads/lore-1') {
60+
if (req.body.ref === config.mailrepo.mirrorRef) {
6561
const queued = await listWorkflowRuns(...a, 'handle-new-mails.yml', 'queued')
6662
if (queued.length) {
6763
context.res.body += [
@@ -73,7 +69,7 @@ module.exports = async (context, req) => {
7369
context.res.body += `triggered ${run.html_url}`
7470
}
7571
} else context.res.body += `Ignoring non-default branches`
76-
} else if (req.body.repository.full_name !== 'git/git') {
72+
} else if (req.body.repository.full_name !== `${config.repo.baseOwner}/${config.repo.name}`) {
7773
context.res = { body: `Ignoring pushes to ${req.body.repository.full_name}` }
7874
} else {
7975
const run = await triggerWorkflowDispatch(
@@ -84,7 +80,7 @@ module.exports = async (context, req) => {
8480
}
8581
)
8682
const extra = []
87-
if (req.body.ref === 'refs/heads/seen') {
83+
if (config.repo.branches.map((name) => `refs/heads/${name}`).includes(req.body.ref)) {
8884
for (const workflow of ['update-prs.yml', 'update-mail-to-commit-notes.yml']) {
8985
if ((await listWorkflowRuns(...a, workflow, 'main', 'queued')).length === 0) {
9086
const run = await triggerWorkflowDispatch(...a, workflow, 'main')
@@ -103,7 +99,7 @@ module.exports = async (context, req) => {
10399
}
104100

105101
/* GitGitGadget works on dscho/git only for testing */
106-
if (repositoryOwner === 'dscho' && comment.user.login !== 'dscho') {
102+
if (repositoryOwner === config.repo.testOwner && comment.user.login !== config.repo.testOwner) {
107103
throw new Error(`Ignoring comment from ${comment.user.login}`);
108104
}
109105

__tests__/index.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ testIssueComment('/test', async (context) => {
162162
testIssueComment('/verify-repository', 'nope', (context) => {
163163
expect(context.done).toHaveBeenCalledTimes(1)
164164
expect(context.res).toEqual({
165-
body: 'Refusing to work on a repository other than gitgitgadget/git or git/git',
165+
body: 'Refusing to work on any repository outside of gitgitgadget, git, dscho',
166166
'status': 403,
167167
})
168168
expect(mockRequest.write).not.toHaveBeenCalled()

0 commit comments

Comments
 (0)