Skip to content
This repository was archived by the owner on Mar 22, 2020. It is now read-only.

Commit 230e4ee

Browse files
committed
before merge to the main engine
1 parent 55b0015 commit 230e4ee

File tree

4 files changed

+92
-90
lines changed

4 files changed

+92
-90
lines changed

BOT.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
# Translate bot
3+
4+
The helpful bot watches the repository and performs following actions:
5+
6+
1. When a PR is created
7+
- PR gets a `review needed` label.
8+
- Review requested from the @translate-(lang) team.
9+
- PR # and author is appended to the progress issue item matching PR title
10+
- if no such item, bot writes a comment to PR suggesting to change the title
11+
2. When PR changes requested by a reviewer
12+
- PR label changes: `review needed` -> `changes requested`
13+
- Bot writes a comment suggesting to comment `/done` when changes are finished
14+
3. When PR comment `/done` appears
15+
- PR label changes back: `changes requested` -> `review needed`
16+
4. When changes are approved
17+
- PR label changes `review needed` -> `needs +1`
18+
- The next reviewer may ask for changes leading to more `review needed/changes requested` cycles
19+
- When a reviewer is satisfied with the PR with `needs +1`, they merge it.
20+
5. When a PR is merged
21+
- The progress issue item is labeled with `[x]`
22+
- The bot sends Congratz
File renamed without changes.

config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const path = require('path');
2-
const fs = require('fs');
2+
const fs = require('fs-extra');
33
const _ = require('lodash');
44

55
const config = {
66
projectRoot: process.cwd(),
77
cacheRoot: path.join(process.cwd(), 'cache'),
8+
backupRoot: path.join(process.cwd(), 'backup'),
89
repoRoot: path.join(process.cwd(), 'repo'),
910
secret: require('/js/secret/translate'),
1011
owner: "iliakan",
@@ -28,6 +29,10 @@ const config = {
2829
}], 'name')
2930
};
3031

32+
fs.ensureDirSync(config.cacheRoot);
33+
fs.ensureDirSync(config.backupRoot);
34+
fs.ensureDirSync(config.repoRoot);
35+
3136
config.langs = {};
3237
for(let file of fs.readdirSync(path.join(__dirname, 'langs'))) {
3338
let lang = require(path.join(__dirname, 'langs', file));

lib/init/createProgressIssue.js

Lines changed: 64 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,8 @@ const octokit = new Octokit({
1717

1818

1919
module.exports = async function(langInfo) {
20-
let issueExists = await findProgressIssue(langInfo);
2120

22-
if (issueExists) {
23-
return;
24-
}
25-
26-
let body = await getText(langInfo.maintainers);
27-
28-
/*
29-
await octokit.issues.create({
30-
owner: 'iliakan',
31-
repo: `${langInfo.code}.${config.repoSuffix}`,
32-
title: `${langInfo.name} Translation Progress`,
33-
body
34-
});
35-
*/
36-
/*
37-
let result = await graphql(`
38-
mutation($body: String!, $title: String!, $repositoryId:ID!) {
39-
createIssue(input: {
40-
body: $body
41-
title: $title
42-
repositoryId: $repositoryId
43-
})
44-
}
45-
`, {
46-
title: "Title Title",
47-
body: "Body Body",
48-
repositoryId: 123
49-
});*/
21+
let body = await getHeader(langInfo);
5022

5123
debug("Getting repo id");
5224

@@ -61,11 +33,17 @@ module.exports = async function(langInfo) {
6133
name: `${langInfo.code}.${config.repoSuffix}`
6234
});
6335

64-
debug("Creating issue");
36+
let progressIssue = await findProgressIssue(langInfo);
37+
38+
39+
if (true) {
40+
//if (!progressIssue) {
41+
body += await getInitialList(langInfo);
42+
debug("Creating issue");
6543

66-
// https://github.com/MichaelJCompton/GraphSchemaTools/wiki/Example-Mutations-and-Queries
67-
// https://developer.github.com/v4/guides/forming-calls/#about-mutations
68-
let result = await graphql(`
44+
// https://github.com/MichaelJCompton/GraphSchemaTools/wiki/Example-Mutations-and-Queries
45+
// https://developer.github.com/v4/guides/forming-calls/#about-mutations
46+
await graphql(`
6947
mutation($input: CreateIssueInput!) {
7048
createIssue(input: $input) {
7149
issue {
@@ -74,86 +52,79 @@ module.exports = async function(langInfo) {
7452
}
7553
}
7654
`, {
77-
input: {
78-
title: `${langInfo.name} Translation Progress`,
79-
body,
80-
repositoryId: repository.id
81-
}
82-
});
55+
input: {
56+
title: `${langInfo.name} Translation Progress`,
57+
body,
58+
repositoryId: repository.id
59+
}
60+
});
61+
} else {
62+
console.log(progressIssue);
63+
}
8364

84-
debug('Created issue to track translation progress.');
8565

86-
};
8766

88-
async function checkIssueExists(langCode) {
89-
90-
debug("Looking for progress issue");
91-
92-
// https://help.github.com/en/articles/understanding-the-search-syntax
93-
// https://help.github.com/en/articles/searching-issues-and-pull-requests
94-
const {search: {nodes}} = await graphql(`
95-
query {
96-
search(
97-
type: ISSUE
98-
query: "repo:${config.org}/${langCode}.${config.repoSuffix} Translation Progress in:title is:open"
99-
first: 1
100-
) {
101-
nodes {
102-
... on Issue {
103-
title
104-
body
105-
createdAt
106-
lastEditedAt
107-
number
108-
repository {
109-
name
110-
}
111-
}
112-
}
113-
}
114-
}
115-
`);
67+
debug('Created issue to track translation progress.');
11668

69+
};
11770

118-
debug("Found issues: " + nodes.length)
119-
return nodes.length > 0;
120-
}
12171

12272
// https://github.com/tesseralis/is-react-translated-yet/blob/master/src/LangList.js
123-
async function getText(maintainers) {
124-
125-
let tree = await request('https://javascript.info/tutorial/tree', {
126-
json: true
127-
});
73+
async function getHeader(langInfo) {
12874

12975
let text = `
13076
## Maintainer List
13177
132-
${maintainers.map(maintainer => `@${maintainer}`).join(', ')}
78+
${langInfo.maintainers.map(maintainer => `@${maintainer}`).join(', ')}
13379
13480
## For New Translators
13581
136-
To translate a page:
137-
138-
1. Check that no one else has claimed your page in the checklist and comments below.
139-
2. Comment below with the name of the page you would like to translate. **Please take only one page at a time**.
140-
3. Clone this repo, translate your page, and submit a pull request!
82+
<details><summary><b>Please read this first (click to open)</b></summary>
83+
<p>
84+
To translate an article:
14185
142-
Before contributing, read the glossary and style guide (once they exist) to understand how to translate various technical and React-specific terms.
86+
1. Check that no one else has claimed your article in the checklist below.
87+
2. Comment below with the title of the article that you would like to translate, e.g. \`An Introduction to JavaScript\`.
88+
- **Please take only one article at a time**.
89+
3. Fork this repo, translate the article in your fork and submit a pull request!
90+
- The pull request title should be same as the article, e.g. \`An Introduction to JavaScript\` (just like comment)
14391
14492
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.
93+
</p>
94+
</details>
14595
14696
## For Maintainers
14797
148-
When someone volunteers, edit this issue with the username of the volunteer, and with the PR. Ex:
98+
<details><summary><b>Click to open</b></summary>
99+
<p>
100+
Please let others know what you do, on community boards and chats, invite them to join. Translations become better if more people see them.
101+
102+
For teams we suggest that an article has 2 reviews to be merged.
103+
104+
Translalions are tracked below, like this:
105+
106+
* [ ] [Home Page](url) (@iliakan) #1
107+
108+
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>.
149109
150-
* [ ] Home Page (@iliakan) #1
110+
If something doesn't work right, please contact @iliakan.
151111
152-
When PRs are merged, make sure to mark that page as completed!
112+
</p>
113+
</details>
153114
154115
Only maintainers can check/uncheck items below. If you're not, please write in a comment what you take to translate.
155116
`;
156117

118+
return text;
119+
120+
}
121+
122+
async function getInitialList(langInfo) {
123+
let tree = await request('https://javascript.info/tutorial/tree', {
124+
json: true
125+
});
126+
127+
let text = '';
157128

158129
for (let root of tree.roots) {
159130
let section = tree.bySlugMap[root];
@@ -168,13 +139,17 @@ Only maintainers can check/uncheck items below. If you're not, please write in a
168139
text += `\n### ${entry.title}\n\n`;
169140

170141
for (let slug of entry.children) {
171-
text += `* [ ] ${tree.bySlugMap[slug].title}\n`;
142+
let child = tree.bySlugMap[slug];
143+
// console.log(child);
144+
text += `* [ ] [${child.title}](${child.githubLink})\n`;
172145
}
173146
} else {
174-
text += `* [ ] ${tree.bySlugMap[entrySlug].title}\n`;
147+
let child = tree.bySlugMap[entrySlug];
148+
text += `* [ ] [${child.title}](${child.githubLink})\n`;
175149
}
176150
}
177151
}
178152

153+
179154
return text;
180155
}

0 commit comments

Comments
 (0)