-
Notifications
You must be signed in to change notification settings - Fork 317
/
generate-fixtures.js
executable file
·128 lines (119 loc) · 2.88 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env node
const fs = require('node:fs')
const path = require('node:path')
const fetch = require('node-fetch')
const {
findCommitsWithAssociatedPullRequestsQuery,
findCommitsWithPathChangesQuery,
} = 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',
},
]
const runQuery = (kind, repo, body) => {
const options = {
body,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `bearer ${GITHUB_TOKEN}`,
},
}
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-${kind}-${repo.branch}.json`
),
string + '\n'
)
})
.catch(console.error)
}
for (const repo of repos) {
runQuery(
'commits',
repo,
JSON.stringify({
query: findCommitsWithAssociatedPullRequestsQuery,
variables: {
owner: repo.owner,
name: REPO_NAME,
targetCommitish: repo.branch,
withPullRequestBody: true,
withPullRequestURL: true,
withBaseRefName: true,
withHeadRefName: true,
},
})
)
runQuery(
'include-null-path',
repo,
JSON.stringify({
query: findCommitsWithPathChangesQuery,
variables: {
owner: repo.owner,
name: REPO_NAME,
targetCommitish: repo.branch,
withPullRequestBody: true,
withPullRequestURL: true,
withBaseRefName: true,
withHeadRefName: true,
path: null,
},
})
)
runQuery(
'include-path-src-5.md',
repo,
JSON.stringify({
query: findCommitsWithPathChangesQuery,
variables: {
owner: repo.owner,
name: REPO_NAME,
targetCommitish: repo.branch,
withPullRequestBody: true,
withPullRequestURL: true,
withBaseRefName: true,
withHeadRefName: true,
path: 'src/5.md',
},
})
)
}