forked from release-drafter/release-drafter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-fixtures.js
executable file
·81 lines (75 loc) · 1.96 KB
/
generate-fixtures.js
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
#!/usr/bin/env node
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch')
const { findCommitsWithAssociatedPullRequestsQuery } = require('../lib/commits')
const REPO_NAME = 'release-drafter-test-repo'
const GITHUB_GRAPHQL_API_ENDPOINT = 'https://api.github.com/graphql'
const GITHUB_TOKEN = process.env.GITHUB_TOKEN
if (!GITHUB_TOKEN) {
throw new Error(
"GitHub's GraphQL API requires a token. Please pass a valid token (GITHUB_TOKEN) as an env variable, no scopes are required."
)
}
const repos = [
{
owner: 'TimonVS',
branch: 'merge-commit',
},
{
owner: 'TimonVS',
branch: 'rebase-merging',
},
{
owner: 'TimonVS',
branch: 'squash-merging',
},
{
owner: 'TimonVS',
branch: 'overlapping-label',
},
{
owner: 'jetersen',
branch: 'forking',
},
]
for (const repo of repos) {
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `bearer ${GITHUB_TOKEN}`,
},
body: JSON.stringify({
query: findCommitsWithAssociatedPullRequestsQuery,
variables: {
owner: repo.owner,
name: REPO_NAME,
targetCommitish: repo.branch,
withPullRequestBody: true,
withPullRequestURL: true,
withBaseRefName: true,
withHeadRefName: true,
},
}),
}
fetch(GITHUB_GRAPHQL_API_ENDPOINT, options)
.then((response) => response.json())
.then((data) => {
// hack the generated to reduce massive rewrite inside the tests
// basically duplicating the possible configs 🤯
let string = JSON.stringify(data, null, 2).replace(
/TimonVS\/release-drafter-test-repo/g,
'toolmantim/release-drafter-test-project'
)
fs.writeFileSync(
path.resolve(
__dirname,
'../test/fixtures/__generated__',
`graphql-commits-${repo.branch}.json`
),
string + '\n'
)
})
.catch(console.error)
}