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 8
Expand file tree
/
Copy pathcreateProgressIssue.js
More file actions
155 lines (111 loc) · 4.08 KB
/
Copy pathcreateProgressIssue.js
File metadata and controls
155 lines (111 loc) · 4.08 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
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 body = await getHeader(langInfo);
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}`
});
let progressIssue = await findProgressIssue(langInfo);
if (true) {
//if (!progressIssue) {
body += await getInitialList(langInfo);
debug("Creating issue");
// https://github.com/MichaelJCompton/GraphSchemaTools/wiki/Example-Mutations-and-Queries
// https://developer.github.com/v4/guides/forming-calls/#about-mutations
await graphql(`
mutation($input: CreateIssueInput!) {
createIssue(input: $input) {
issue {
id
}
}
}
`, {
input: {
title: `${langInfo.name} Translation Progress`,
body,
repositoryId: repository.id
}
});
} else {
console.log(progressIssue);
}
debug('Created issue to track translation progress.');
};
// https://github.com/tesseralis/is-react-translated-yet/blob/master/src/LangList.js
async function getHeader(langInfo) {
let text = `
## Maintainer List
${langInfo.maintainers.map(maintainer => `@${maintainer}`).join(', ')}
## For New Translators
<details><summary><b>Please read this first (click to open)</b></summary>
<p>
To translate an article:
1. Check that no one else has claimed your article in the checklist below.
2. Comment below with the title of the article that you would like to translate, e.g. \`An Introduction to JavaScript\`.
- **Please take only one article at a time**.
3. Fork this repo, translate the article in your fork and submit a pull request!
- The pull request title should be same as the article, e.g. \`An Introduction to JavaScript\` (just like comment)
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.
</p>
</details>
## For Maintainers
<details><summary><b>Click to open</b></summary>
<p>
Please let others know what you do, on community boards and chats, invite them to join. Translations become better if more people see them.
For teams we suggest that an article has 2 reviews to be merged.
Translalions are tracked below, like this:
* [ ] [Home Page](url) (@iliakan) #1
There's a helper bot to track translations, you can read more about it at <https://github.com/javascript-tutorial/translate/edit/master/BOT.md>.
If something doesn't work right, please contact @iliakan.
</p>
</details>
Only maintainers can check/uncheck items below. If you're not, please write in a comment what you take to translate.
`;
return text;
}
async function getInitialList(langInfo) {
let tree = await request('https://javascript.info/tutorial/tree', {
json: true
});
let text = '';
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) {
let child = tree.bySlugMap[slug];
// console.log(child);
text += `* [ ] [${child.title}](${child.githubLink})\n`;
}
} else {
let child = tree.bySlugMap[entrySlug];
text += `* [ ] [${child.title}](${child.githubLink})\n`;
}
}
}
return text;
}