-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMostRecentLinkedPullRequest.js
45 lines (44 loc) · 1.26 KB
/
getMostRecentLinkedPullRequest.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
const { PullRequest } = require('../server/db')
async function getMostRecentLinkedPullRequest(
/*owner:*/ owner,
/*repo:*/ repo_id,
/*defaultHash:*/ defaultHash,
/*contributor:*/ contributor_id,
/*side:*/ side,
) {
try {
let pr = await PullRequest.findOne({
where: { repo_id: repo_id, defaultHash: defaultHash },
})
console.log('pr.state = ' + pr.state)
console.log('pr.fork_branch = ' + pr.fork_branch)
if (pr.childDefaultHash !== pr.defaultHash) {
await getMostRecentLinkedPullRequest(
owner,
repo_id,
pr.childDefaultHash,
contributor_id,
side,
)
}
return {
status: 200,
state: pr.state,
repo_id: pr.repo_id,
fork_branch: pr.fork_branch,
defaultHash: pr.defaultHash,
childDefaultHash: pr.childDefaultHash,
}
} catch (error) {
console.log(error)
return {
status: 500,
state: '',
repo_id: repo_id,
fork_branch: '',
defaultHash: '',
childDefaultHash: '',
}
}
}
module.exports = getMostRecentLinkedPullRequest