Skip to content

Commit

Permalink
review updates and added test for merge queue
Browse files Browse the repository at this point in the history
  • Loading branch information
snowystinger committed Sep 20, 2024
1 parent d94c3f6 commit bd9fecc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 27 deletions.
59 changes: 32 additions & 27 deletions checker/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async function main (params) {
const ow = openwhisk();

if (isMergeQueue) {
const res = await set_green_is_bot(ow, {
const res = await set_green_has_signed_cla(ow, {
commit_sha: params.merge_group.head_sha,
org: params.repository.owner.login,
repo: params.repository.name,
Expand Down Expand Up @@ -209,32 +209,8 @@ async function check_cla (ow, args) {
if (usernames.map(function (item) { return item.toLowerCase(); }).includes(args.user.toLowerCase())) {
// If the username exists in the response from the lookup action, then we
// can render a green checkmark on the PR!
let check_res;
try {
check_res = await ow.actions.invoke({
name: utils.SETGITHUBCHECK,
blocking: true,
result: true,
params: {
installation_id: args.installation_id,
org: args.org,
repo: args.repo,
sha: args.commit_sha,
status: 'completed',
start_time: args.start_time,
conclusion: 'success',
title: 'CLA Signed',
summary: 'A Signed CLA has been found for the GitHub.com user ' + args.user
}
});
} catch (e) {
return utils.action_error(e, 'Error invoking setgithubcheck when CLA was found.');
}

return {
statusCode: 200,
body: check_res.title
};
const check = await set_green_has_signed_cla(ow, args);
return check;
} else {
try {
const check = await action_required(ow, args);
Expand Down Expand Up @@ -346,4 +322,33 @@ If you believe this was a mistake, please report an issue at [adobe/cla-bot](htt
};
}

async function set_green_has_signed_cla (ow, args) {
let result;
try {
result = await ow.actions.invoke({
name: utils.SETGITHUBCHECK,
blocking: true,
result: true,
params: {
installation_id: args.installation_id,
org: args.org,
repo: args.repo,
sha: args.commit_sha,
status: 'completed',
start_time: args.start_time,
conclusion: 'success',
title: 'CLA Signed',
summary: 'A Signed CLA has been found for the GitHub.com user ' + args.user
}
});
} catch (e) {
return utils.action_error(e, 'Error invoking setgithubcheck when CLA was found.');
}

return {
statusCode: 200,
body: result.title
};
}

exports.main = main;
35 changes: 35 additions & 0 deletions test/unit/checker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,4 +884,39 @@ describe('checker action', function () {
});
});
});
describe('merge queue', function () {
it('should pass the PR through the merge queue because the CLA would have already been found', async function () {
const params = {
merge_group: {
head_sha: '12345'
},
repository: {
owner: {
login: 'adobe'
},
name: 'photoshop'
},
action: 'checks_requested'
};

const invoke_spy = jest.fn().mockImplementationOnce((args) => {
return {
title: args.params.title
};
});
openWhisk.mockImplementation(() => {
return {
actions: {
invoke: invoke_spy
}
};
});
const response = await checker.main(params);
const action_invoke_args = invoke_spy.mock.calls[0][0];
expect(action_invoke_args.name).toBe('cla-setgithubcheck');
expect(action_invoke_args.params.conclusion).toBe('success');
expect(action_invoke_args.params.title).toContain('CLA Signed');
expect(response.statusCode).toBe(200);
});
});
});

0 comments on commit bd9fecc

Please sign in to comment.