forked from NicholasBoll/github-migration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.js
84 lines (76 loc) · 2.42 KB
/
check.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
const debug = require('debug')
const fs = require('fs-extra')
const config = require('./config')
const _ = require('lodash')
// var checkCommits = function(callback) {
// var comments = JSON.parse(fs.readFileSync(repo + '/comments.json'));
// async.eachSeries(comments.concat(issues), function(item, itemCallback) {
// if (item.base) { // this is a pull request
// checkCommitExists(item.base.sha, itemCallback);
// } else if (reviewComment(item)) {
// checkCommitExists(item.original_commit_id, itemCallback);
// } else if (commitComment(item)) {
// checkCommitExists(item.commit_id, itemCallback);
// } else {
// itemCallback();
// }
// }, function(err) {
// fs.writeFileSync(repo + '/missingCommits.json', JSON.stringify(_.unique(missingCommits)));
// callback();
// });
// }
/**
*
* @param {{}[]} comments
* @param {{}[]} commits
*/
const getOrphanedPullRequestCommits = (comments, commits) => {
return comments.reduce((result, comment) => {
const sha = comment.original_commit_id
if (!commits.find((commit) => commit.sha === sha)) {
result.push(sha)
debug('pr')(`Missing commit: ${sha}`)
}
return result
}, [])
}
/**
*
* @param {{}[]} comments
* @param {{}[]} commits
*/
const getOrphanedIssueCommits = (comments, commits) => {
return comments.reduce((result, comment) => {
const sha = comment.original_commit_id
if (!commits.find((commit) => commit.sha === sha)) {
result.push(sha)
debug('pr')(`Missing commit: ${sha}`)
}
return result
}, [])
}
/**
*
* @param {{}[]} comments
* @param {{}[]} commits
*/
const getOrphanedCommitCommits = (comments, commits) => {
return comments.reduce((result, comment) => {
const sha = comment.commit_id
if (!commits.find((commit) => commit.sha === sha)) {
result.push(sha)
debug('pr')(`Missing commit: ${sha}`)
}
return result
}, [])
}
const main = async () => {
const commits = JSON.parse(await fs.readFile(`${config.source.repo}/commits.json`))
const orphanedCommits = _.uniq([].concat(
getOrphanedPullRequestCommits(JSON.parse(await fs.readFile(`${config.source.repo}/pull-comments.json`)), commits),
getOrphanedCommitCommits(JSON.parse(await fs.readFile(`${config.source.repo}/comments.json`)), commits),
))
console.log(orphanedCommits.length)
await fs.writeFile(`${config.source.repo}/missing-commits.json`, JSON.stringify(orphanedCommits, null, ' '))
}
main()