This repository was archived by the owner on Mar 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcreateProgressIssue.js
More file actions
180 lines (140 loc) · 4.55 KB
/
createProgressIssue.js
File metadata and controls
180 lines (140 loc) · 4.55 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
const request = require('request-promise');
const config = require("../../config");
const findProgressIssue = require('../findProgressIssue');
const debug = require('debug')('init:createProgressIssue');
const Octokit = require('@octokit/rest');
const graphql = require('@octokit/graphql').defaults({
headers: {
authorization: `token ${config.secret.github.token}`,
accept: 'application/vnd.github.elektra-preview+json'
}
});
const octokit = new Octokit({
auth: `token ${config.secret.github.token}`
});
module.exports = async function(langInfo) {
let issueExists = await findProgressIssue(langInfo);
if (issueExists) {
return;
}
let body = await getText(langInfo.maintainers);
/*
await octokit.issues.create({
owner: 'iliakan',
repo: `${langInfo.code}.${config.repoSuffix}`,
title: `${langInfo.name} Translation Progress`,
body
});
*/
/*
let result = await graphql(`
mutation($body: String!, $title: String!, $repositoryId:ID!) {
createIssue(input: {
body: $body
title: $title
repositoryId: $repositoryId
})
}
`, {
title: "Title Title",
body: "Body Body",
repositoryId: 123
});*/
debug("Getting repo id");
const {repositoryOwner: {repository}} = await graphql(`query($owner: String!, $name: String!) {
repositoryOwner(login:$owner) {
repository(name:$name) {
id
}
}
}`, {
owner: config.org,
name: `${langInfo.code}.${config.repoSuffix}`
});
debug("Creating issue");
// https://github.com/MichaelJCompton/GraphSchemaTools/wiki/Example-Mutations-and-Queries
// https://developer.github.com/v4/guides/forming-calls/#about-mutations
let result = await graphql(`
mutation($input: CreateIssueInput!) {
createIssue(input: $input) {
issue {
id
}
}
}
`, {
input: {
title: `${langInfo.name} Translation Progress`,
body,
repositoryId: repository.id
}
});
debug('Created issue to track translation progress.');
};
async function checkIssueExists(langCode) {
debug("Looking for progress issue");
// https://help.github.com/en/articles/understanding-the-search-syntax
// https://help.github.com/en/articles/searching-issues-and-pull-requests
const {search: {nodes}} = await graphql(`
query {
search(
type: ISSUE
query: "repo:${config.org}/${langCode}.${config.repoSuffix} Translation Progress in:title is:open"
first: 1
) {
nodes {
... on Issue {
title
body
createdAt
lastEditedAt
number
repository {
name
}
}
}
}
}
`);
debug("Found issues: " + nodes.length)
return nodes.length > 0;
}
// https://github.com/tesseralis/is-react-translated-yet/blob/master/src/LangList.js
async function getText(maintainers) {
let tree = await request('https://javascript.info/tutorial/tree', {
json: true
});
let text = `
## Maintainer List
${maintainers.map(maintainer => `@${maintainer.github}`).join(', ')}
## For New Translators
To translate a page:
1. Check that no one else has claimed your page in the checklist and comments below.
2. Comment below with the name of the page you would like to translate. **Please take only one page at a time**.
3. Clone this repo, translate your page, and submit a pull request!
Before contributing, read the glossary and style guide (once they exist) to understand how to translate various technical and React-specific terms.
Please be prompt with your translations! If you find find that you can't commit any more, let the maintainers know so they can assign the page to someone else.
## For Maintainers
When someone volunteers, edit this issue with the username of the volunteer, and with the PR. Ex:
* [ ] Home Page (@iliakan) #1
When PRs are merged, make sure to mark that page as completed!
Only maintainers can check/uncheck items below. If you're not, please write in a comment what you take to translate.
`;
for (let root of tree.roots) {
let section = tree.bySlugMap[root];
text += `\n## ${section.title}\n\n`;
for (let entrySlug of section.children) {
let entry = tree.bySlugMap[entrySlug];
if (entry.isFolder) {
text += `\n### ${entry.title}\n\n`;
for (let slug of entry.children) {
text += `* [ ] ${tree.bySlugMap[slug].title}\n`;
}
} else {
text += `* [ ] ${tree.bySlugMap[entrySlug].title}\n`;
}
}
}
return text;
}