Skip to content

Commit 20907da

Browse files
authored
Add fork payload and tests (#25)
1 parent b183d6d commit 20907da

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,25 @@ const renderMessage = require('./lib/message');
88
async function run() {
99
try {
1010
console.log(`action: ${github.context.payload.action}`);
11-
console.log(`payload: ${JSON.stringify(github.context.payload)}`);
11+
console.log(`[data] payload: ${JSON.stringify(github.context.payload)}`);
1212

1313
const config = new Config(core);
14-
console.log(`config: ${JSON.stringify(config)}`);
14+
console.log(`[data] config: ${JSON.stringify(config)}`);
1515

1616
const pull = new Pull(github.context.payload);
17-
console.log(`pull: ${JSON.stringify(pull)}`);
17+
console.log(`[data] pull (payload): ${JSON.stringify(pull)}`);
1818

1919
const token = core.getInput('GITHUB_TOKEN');
2020
const octokit = new github.GitHub(token);
2121

22+
console.log(`[info] get reviews`);
2223
const reviews = await octokit.pulls.listReviews({
2324
owner: pull.owner,
2425
repo: pull.repo,
2526
pull_number: pull.pull_number
2627
});
2728

29+
console.log(`[info] get checks`);
2830
const checks = await octokit.checks.listForRef({
2931
owner: pull.owner,
3032
repo: pull.repo,
@@ -33,6 +35,7 @@ async function run() {
3335

3436
pull.compileReviews(reviews);
3537
pull.compileChecks(checks);
38+
console.log(`[data] pull (checks + reviews): ${JSON.stringify(pull)}`);
3639

3740
console.log(`merge: ${pull.canMerge(config)}`);
3841

lib/pull.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,28 @@ class Pull {
9494
* @param {Object} checks check data from pull request
9595
*/
9696
compileChecks(checks) {
97-
const data = checks.data.check_runs;
98-
let compiled = {
99-
total: checks.data.total_count,
100-
completed: 0,
101-
success: 0
102-
};
97+
if (!!checks && !!checks.data) {
98+
const data = checks.data.check_runs;
99+
let compiled = {
100+
total: checks.data.total_count,
101+
completed: 0,
102+
success: 0
103+
};
104+
105+
if (data && Object.keys(data).length > 0) {
106+
data.forEach(element => {
107+
if (element.status === "completed") {
108+
compiled.completed++;
109+
}
103110

104-
if (data && Object.keys(data).length > 0) {
105-
data.forEach(element => {
106-
if (element.status === "completed") {
107-
compiled.completed++;
108-
}
111+
if (element.conclusion === "success") {
112+
compiled.success++;
113+
}
114+
});
115+
}
109116

110-
if (element.conclusion === "success") {
111-
compiled.success++;
112-
}
113-
});
117+
this.checks = compiled;
114118
}
115-
116-
this.checks = compiled;
117119
}
118120

119121
/**

0 commit comments

Comments
 (0)