Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
#use-dco-flag: true - If you are using DCO instead of CLA
#pr-number: pull request number - Required only if the job was not triggered with a pull_request event

```

Expand Down Expand Up @@ -138,6 +139,7 @@ This PAT should have repo scope and is only required if you have configured to s
| `custom-pr-sign-comment` | _optional_ | The signature to be committed in order to sign the CLA. | I have read the Developer Terms Document and I hereby accept the Terms |
| `custom-allsigned-prcomment` | _optional_ | pull request comment when everyone has signed | All Contributors have signed the CLA. |
| `lock-pullrequest-aftermerge` | _optional_ | Boolean input for locking the pull request after merging. Default is set to `true`. It is highly recommended to lock the Pull Request after merging so that the Contributors won't be able to revoke their signature comments after merge | false |
| `pr-number` | _optional_ | pull request number (required when the workflow event is not pull_request / pull_request_target). | 42 |

## Contributors

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ inputs:
lock-pullrequest-aftermerge:
description: "Will lock the pull request after merge so that the signature the contributors cannot revoke their signature comments after merge"
default: "true"
pr-number:
description: "pull request number (required when the workflow event is not pull_request / pull_request_target)"
runs:
using: "node16"
main: 'dist/index.js'
37 changes: 23 additions & 14 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", { value: true });
const octokit_1 = __webpack_require__(28);
const github_1 = __webpack_require__(469);
const getInputs_1 = __webpack_require__(555);
function getCommitters() {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -727,15 +728,15 @@ function getCommitters() {
}`.replace(/ /g, ''), {
owner: github_1.context.repo.owner,
name: github_1.context.repo.repo,
number: github_1.context.issue.number,
number: (0, getInputs_1.getPrNumber)(github_1.context.issue.number),
cursor: ''
});
response.repository.pullRequest.commits.edges.forEach(edge => {
const committer = extractUserFromCommit(edge.node.commit);
let user = {
name: committer.login || committer.name,
id: committer.databaseId || '',
pullRequestNo: github_1.context.issue.number
pullRequestNo: (0, getInputs_1.getPrNumber)(github_1.context.issue.number)
};
if (committers.length === 0 || committers.map((c) => {
return c.name;
Expand Down Expand Up @@ -1648,10 +1649,11 @@ exports.lockPullRequest = void 0;
const octokit_1 = __webpack_require__(28);
const core = __importStar(__webpack_require__(470));
const github_1 = __webpack_require__(469);
const getInputs_1 = __webpack_require__(555);
function lockPullRequest() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Locking the Pull Request to safe guard the Pull Request CLA Signatures');
const pullRequestNo = github_1.context.issue.number;
const pullRequestNo = (0, getInputs_1.getPrNumber)(github_1.context.issue.number);
try {
yield octokit_1.octokit.issues.lock({
owner: github_1.context.repo.owner,
Expand Down Expand Up @@ -1903,7 +1905,7 @@ exports.createFile = createFile;
function updateFile(sha, claFileContent, reactedCommitters) {
return __awaiter(this, void 0, void 0, function* () {
const octokitInstance = isRemoteRepoOrOrgConfigured() ? (0, octokit_1.getPATOctokit)() : (0, octokit_1.getDefaultOctokitClient)();
const pullRequestNo = github_1.context.issue.number;
const pullRequestNo = input.getPrNumber(github_1.context.issue.number);
const owner = github_1.context.issue.owner;
const repo = github_1.context.issue.repo;
claFileContent === null || claFileContent === void 0 ? void 0 : claFileContent.signedContributors.push(...reactedCommitters.newSigned);
Expand Down Expand Up @@ -2088,7 +2090,7 @@ function dco(signed, committerMap) {
`;
if (committersCount > 1 && committerMap && committerMap.signed && committerMap.notSigned) {
text += `**${committerMap.signed.length}** out of **${committerMap.signed.length + committerMap.notSigned.length}** committers have signed the DCO.`;
committerMap.signed.forEach(signedCommitter => { text += `<br/>:white_check_mark: @${signedCommitter.name}`; });
committerMap.signed.forEach(signedCommitter => { text += `<br/>:white_check_mark: (${signedCommitter.name})[https://github.com/${signedCommitter.name}]`; });
committerMap.notSigned.forEach(unsignedCommitter => {
text += `<br/>:x: @${unsignedCommitter.name}`;
});
Expand Down Expand Up @@ -2122,7 +2124,7 @@ function cla(signed, committerMap) {
`;
if (committersCount > 1 && committerMap && committerMap.signed && committerMap.notSigned) {
text += `**${committerMap.signed.length}** out of **${committerMap.signed.length + committerMap.notSigned.length}** committers have signed the CLA.`;
committerMap.signed.forEach(signedCommitter => { text += `<br/>:white_check_mark: @${signedCommitter.name}`; });
committerMap.signed.forEach(signedCommitter => { text += `<br/>:white_check_mark: (${signedCommitter.name})[https://github.com/${signedCommitter.name}]`; });
committerMap.notSigned.forEach(unsignedCommitter => {
text += `<br/>:x: @${unsignedCommitter.name}`;
});
Expand Down Expand Up @@ -2213,6 +2215,7 @@ const github_1 = __webpack_require__(469);
const persistence_1 = __webpack_require__(362);
const pullRerunRunner_1 = __webpack_require__(633);
const core = __importStar(__webpack_require__(470));
const getInputs_1 = __webpack_require__(555);
function setupClaCheck() {
return __awaiter(this, void 0, void 0, function* () {
let committerMap = getInitialCommittersMap();
Expand All @@ -2233,7 +2236,7 @@ function setupClaCheck() {
return (0, pullRerunRunner_1.reRunLastWorkFlowIfRequired)();
}
else {
core.setFailed(`Committers of Pull Request number ${github_1.context.issue.number} have to sign the CLA 📝`);
core.setFailed(`Committers of Pull Request number ${(0, getInputs_1.getPrNumber)(github_1.context.issue.number)} have to sign the CLA 📝`);
}
}
catch (err) {
Expand Down Expand Up @@ -2277,7 +2280,7 @@ function createClaFileAndPRComment(committers, committerMap) {
const initialContentBinary = Buffer.from(initialContentString).toString('base64');
yield (0, persistence_1.createFile)(initialContentBinary).catch(error => core.setFailed(`Error occurred when creating the signed contributors file: ${error.message || error}. Make sure the branch where signatures are stored is NOT protected.`));
yield (0, pullRequestComment_1.default)(committerMap, committers);
throw new Error(`Committers of pull request ${github_1.context.issue.number} have to sign the CLA`);
throw new Error(`Committers of pull request ${(0, getInputs_1.getPrNumber)(github_1.context.issue.number)} have to sign the CLA`);
});
}
function prepareCommiterMap(committers, claFileContent) {
Expand Down Expand Up @@ -2379,13 +2382,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
const octokit_1 = __webpack_require__(28);
const github_1 = __webpack_require__(469);
const getInputs_1 = __webpack_require__(555);
const getInputs_2 = __webpack_require__(555);
function signatureWithPRComment(committerMap, committers) {
return __awaiter(this, void 0, void 0, function* () {
let repoId = github_1.context.payload.repository.id;
let prResponse = yield octokit_1.octokit.issues.listComments({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
issue_number: github_1.context.issue.number
issue_number: (0, getInputs_2.getPrNumber)(github_1.context.issue.number)
});
let listOfPRComments = [];
let filteredListOfPRComments = [];
Expand All @@ -2397,7 +2401,7 @@ function signatureWithPRComment(committerMap, committers) {
body: prComment.body.trim().toLowerCase(),
created_at: prComment.created_at,
repoId: repoId,
pullRequestNo: github_1.context.issue.number
pullRequestNo: (0, getInputs_2.getPrNumber)(github_1.context.issue.number)
});
});
listOfPRComments.map(comment => {
Expand Down Expand Up @@ -4494,7 +4498,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.lockPullRequestAfterMerge = exports.getCustomPrSignComment = exports.getUseDcoFlag = exports.getCustomAllSignedPrComment = exports.getCustomNotSignedPrComment = exports.getCreateFileCommitMessage = exports.getSignedCommitMessage = exports.getEmptyCommitFlag = exports.getAllowListItem = exports.getBranch = exports.getPathToDocument = exports.getPathToSignatures = exports.getRemoteOrgName = exports.getRemoteRepoName = void 0;
exports.getPrNumber = exports.lockPullRequestAfterMerge = exports.getCustomPrSignComment = exports.getUseDcoFlag = exports.getCustomAllSignedPrComment = exports.getCustomNotSignedPrComment = exports.getCreateFileCommitMessage = exports.getSignedCommitMessage = exports.getEmptyCommitFlag = exports.getAllowListItem = exports.getBranch = exports.getPathToDocument = exports.getPathToSignatures = exports.getRemoteOrgName = exports.getRemoteRepoName = void 0;
const core = __importStar(__webpack_require__(470));
const getRemoteRepoName = () => {
return core.getInput('remote-repository-name', { required: false });
Expand Down Expand Up @@ -4528,6 +4532,10 @@ const getCustomPrSignComment = () => core.getInput('custom-pr-sign-comment', { r
exports.getCustomPrSignComment = getCustomPrSignComment;
const lockPullRequestAfterMerge = () => core.getInput('lock-pullrequest-aftermerge', { required: false });
exports.lockPullRequestAfterMerge = lockPullRequestAfterMerge;
const getPrNumber = (prNumberFromContext) => prNumberFromContext ?
prNumberFromContext :
Number(core.getInput('pr-number', { required: false }));
exports.getPrNumber = getPrNumber;


/***/ }),
Expand Down Expand Up @@ -22039,6 +22047,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.reRunLastWorkFlowIfRequired = void 0;
const github_1 = __webpack_require__(469);
const octokit_1 = __webpack_require__(28);
const getInputs_1 = __webpack_require__(555);
const core = __importStar(__webpack_require__(470));
// Note: why this re-run of the last failed CLA workflow status check is explained this issue https://github.com/cla-assistant/github-action/issues/39
function reRunLastWorkFlowIfRequired() {
Expand Down Expand Up @@ -22066,7 +22075,7 @@ function getBranchOfPullRequest() {
const pullRequest = yield octokit_1.octokit.pulls.get({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
pull_number: github_1.context.issue.number
pull_number: (0, getInputs_1.getPrNumber)(github_1.context.issue.number)
});
return pullRequest.data.head.ref;
});
Expand Down Expand Up @@ -23015,7 +23024,7 @@ function createComment(signed, committerMap) {
yield octokit_1.octokit.issues.createComment({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
issue_number: github_1.context.issue.number,
issue_number: (0, getInputs_1.getPrNumber)(github_1.context.issue.number),
body: (0, pullRequestCommentContent_1.commentContent)(signed, committerMap)
}).catch(error => { throw new Error(`Error occured when creating a pull request comment: ${error.message}`); });
});
Expand All @@ -23033,7 +23042,7 @@ function updateComment(signed, committerMap, claBotComment) {
function getComment() {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield octokit_1.octokit.issues.listComments({ owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, issue_number: github_1.context.issue.number });
const response = yield octokit_1.octokit.issues.listComments({ owner: github_1.context.repo.owner, repo: github_1.context.repo.repo, issue_number: (0, getInputs_1.getPrNumber)(github_1.context.issue.number) });
//TODO: check the below regex
// using a `string` true or false purposely as github action input cannot have a boolean value
if ((0, getInputs_1.getUseDcoFlag)() === 'true') {
Expand Down
2 changes: 1 addition & 1 deletion src/addEmptyCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function addEmptyCommit() {
const pullRequestResponse = await octokit.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.issue!.number
pull_number: input.getPrNumber(context.payload.issue!.number)
})

const baseCommit = await octokit.git.getCommit({
Expand Down
7 changes: 3 additions & 4 deletions src/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { octokit } from './octokit'
import { context } from '@actions/github'
import { CommittersDetails } from './interfaces'


import { getPrNumber } from './shared/getInputs'

export default async function getCommitters(): Promise<CommittersDetails[]> {
try {
Expand Down Expand Up @@ -48,15 +47,15 @@ export default async function getCommitters(): Promise<CommittersDetails[]> {
}`.replace(/ /g, ''), {
owner: context.repo.owner,
name: context.repo.repo,
number: context.issue.number,
number: getPrNumber(context.issue.number),
cursor: ''
})
response.repository.pullRequest.commits.edges.forEach(edge => {
const committer = extractUserFromCommit(edge.node.commit)
let user = {
name: committer.login || committer.name,
id: committer.databaseId || '',
pullRequestNo: context.issue.number
pullRequestNo: getPrNumber(context.issue.number)
}
if (committers.length === 0 || committers.map((c) => {
return c.name
Expand Down
2 changes: 1 addition & 1 deletion src/persistence/persistence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function updateFile(
const octokitInstance: InstanceType<typeof GitHub> =
isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient()

const pullRequestNo = context.issue.number
const pullRequestNo = input.getPrNumber(context.issue.number)
const owner = context.issue.owner
const repo = context.issue.repo

Expand Down
3 changes: 2 additions & 1 deletion src/pullRerunRunner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { context } from '@actions/github'
import { octokit } from './octokit'
import { getPrNumber } from './shared/getInputs'

import * as core from '@actions/core'

Expand Down Expand Up @@ -31,7 +32,7 @@ async function getBranchOfPullRequest(): Promise<string> {
const pullRequest = await octokit.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
pull_number: getPrNumber(context.issue.number)
})

return pullRequest.data.head.ref
Expand Down
7 changes: 3 additions & 4 deletions src/pullrequest/pullRequestComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import {
CommitterMap,
CommittersDetails
} from '../interfaces'
import { getUseDcoFlag } from '../shared/getInputs'

import { getUseDcoFlag, getPrNumber } from '../shared/getInputs'


export default async function prCommentSetup(committerMap: CommitterMap, committers: CommittersDetails[]) {
Expand Down Expand Up @@ -41,7 +40,7 @@ async function createComment(signed: boolean, committerMap: CommitterMap): Promi
await octokit.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
issue_number: getPrNumber(context.issue.number),
body: commentContent(signed, committerMap)
}).catch(error => { throw new Error(`Error occured when creating a pull request comment: ${error.message}`) })
}
Expand All @@ -57,7 +56,7 @@ async function updateComment(signed: boolean, committerMap: CommitterMap, claBot

async function getComment() {
try {
const response = await octokit.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number })
const response = await octokit.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: getPrNumber(context.issue.number) })

//TODO: check the below regex
// using a `string` true or false purposely as github action input cannot have a boolean value
Expand Down
4 changes: 2 additions & 2 deletions src/pullrequest/pullRequestLock.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { octokit } from '../octokit'
import * as core from '@actions/core'
import { context } from '@actions/github'

import { getPrNumber } from '../shared/getInputs'
export async function lockPullRequest() {
core.info('Locking the Pull Request to safe guard the Pull Request CLA Signatures')
const pullRequestNo: number = context.issue.number
const pullRequestNo: number = getPrNumber(context.issue.number)
try {
await octokit.issues.lock(
{
Expand Down
5 changes: 3 additions & 2 deletions src/pullrequest/signatureComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import { CommitterMap, CommittersDetails, ReactedCommitterMap } from '../interfa
import { getUseDcoFlag, getCustomPrSignComment } from '../shared/getInputs'

import * as core from '@actions/core'
import { getPrNumber } from '../shared/getInputs'

export default async function signatureWithPRComment(committerMap: CommitterMap, committers): Promise<ReactedCommitterMap> {

let repoId = context.payload.repository!.id
let prResponse = await octokit.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
issue_number: getPrNumber(context.issue.number)
})
let listOfPRComments = [] as CommittersDetails[]
let filteredListOfPRComments = [] as CommittersDetails[]
Expand All @@ -24,7 +25,7 @@ export default async function signatureWithPRComment(committerMap: CommitterMap,
body: prComment.body.trim().toLowerCase(),
created_at: prComment.created_at,
repoId: repoId,
pullRequestNo: context.issue.number
pullRequestNo: getPrNumber(context.issue.number)
})
})
listOfPRComments.map(comment => {
Expand Down
5 changes: 3 additions & 2 deletions src/setupClaCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from './persistence/persistence'
import { reRunLastWorkFlowIfRequired } from './pullRerunRunner'
import * as core from '@actions/core'
import { getPrNumber } from './shared/getInputs'

export async function setupClaCheck() {
let committerMap = getInitialCommittersMap()
Expand Down Expand Up @@ -48,7 +49,7 @@ export async function setupClaCheck() {
return reRunLastWorkFlowIfRequired()
} else {
core.setFailed(
`Committers of Pull Request number ${context.issue.number} have to sign the CLA 📝`
`Committers of Pull Request number ${getPrNumber(context.issue.number)} have to sign the CLA 📝`
)
}
} catch (err) {
Expand Down Expand Up @@ -106,7 +107,7 @@ async function createClaFileAndPRComment(
)
await prCommentSetup(committerMap, committers)
throw new Error(
`Committers of pull request ${context.issue.number} have to sign the CLA`
`Committers of pull request ${getPrNumber(context.issue.number)} have to sign the CLA`
)
}

Expand Down
5 changes: 5 additions & 0 deletions src/shared/getInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,8 @@ export const getCustomPrSignComment = (): string =>

export const lockPullRequestAfterMerge = (): string =>
core.getInput('lock-pullrequest-aftermerge', { required: false })

export const getPrNumber = (prNumberFromContext: number): number =>
prNumberFromContext ?
prNumberFromContext :
Number(core.getInput('pr-number', { required: false }))