From a9e6bc9a9c9071b228f7f3336f6ff220fff76ea0 Mon Sep 17 00:00:00 2001 From: ibakshay Date: Thu, 9 Feb 2023 10:46:19 +0100 Subject: [PATCH 1/5] test --- dist/index.js | 4 +++ src/persistence/persistence.ts | 51 +++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/dist/index.js b/dist/index.js index 0ca7390c..70b11dc6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1904,6 +1904,7 @@ 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; + console.log(JSON.stringify(github_1.context.issue, null, 3)); claFileContent === null || claFileContent === void 0 ? void 0 : claFileContent.signedContributors.push(...reactedCommitters.newSigned); let contentString = JSON.stringify(claFileContent, null, 2); let contentBinary = Buffer.from(contentString).toString('base64'); @@ -1916,6 +1917,9 @@ function updateFile(sha, claFileContent, reactedCommitters) { ? input .getSignedCommitMessage() .replace('$contributorName', github_1.context.actor) + .replace('$pullRequestNo', github_1.context.issue.number.toString()) + .replace('$owner', github_1.context.issue.owner) + .replace('$repo', github_1.context.issue.repo) : `@${github_1.context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, content: contentBinary, branch: input.getBranch() diff --git a/src/persistence/persistence.ts b/src/persistence/persistence.ts index ecbee079..cbb63bea 100644 --- a/src/persistence/persistence.ts +++ b/src/persistence/persistence.ts @@ -35,30 +35,35 @@ export async function createFile(contentBinary): Promise { }) } -export async function updateFile(sha: string, claFileContent, reactedCommitters: ReactedCommitterMap): Promise { - - const octokitInstance: InstanceType = +export async function updateFile( + sha: string, + claFileContent, + reactedCommitters: ReactedCommitterMap +): Promise { + const octokitInstance: InstanceType = isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient() - const pullRequestNo = context.issue.number - claFileContent?.signedContributors.push(...reactedCommitters.newSigned) - let contentString = JSON.stringify(claFileContent, null, 2) - let contentBinary = Buffer.from(contentString).toString("base64") - await octokitInstance.repos.createOrUpdateFileContents({ - owner: input.getRemoteOrgName() || context.repo.owner, - repo: input.getRemoteRepoName() || context.repo.repo, - path: input.getPathToSignatures(), - sha, - message: input.getSignedCommitMessage() - ? input - .getSignedCommitMessage() - .replace("$contributorName", context.actor) - .replace("$pullRequestNo", context.issue.number.toString()) - .replace("$owner", context.issue.owner) - .replace("$repo", context.issue.repo) - : `@${context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, - content: contentBinary, - branch: input.getBranch() - }) + + const pullRequestNo = context.issue.number + console.log(JSON.stringify(context.issue, null, 3)) + claFileContent?.signedContributors.push(...reactedCommitters.newSigned) + let contentString = JSON.stringify(claFileContent, null, 2) + let contentBinary = Buffer.from(contentString).toString('base64') + await octokitInstance.repos.createOrUpdateFileContents({ + owner: input.getRemoteOrgName() || context.repo.owner, + repo: input.getRemoteRepoName() || context.repo.repo, + path: input.getPathToSignatures(), + sha, + message: input.getSignedCommitMessage() + ? input + .getSignedCommitMessage() + .replace('$contributorName', context.actor) + .replace('$pullRequestNo', context.issue.number.toString()) + .replace('$owner', context.issue.owner) + .replace('$repo', context.issue.repo) + : `@${context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, + content: contentBinary, + branch: input.getBranch() + }) } function isRemoteRepoOrOrgConfigured(): boolean { From d552eddd1715bce31fa9cfde03dda7a247a59242 Mon Sep 17 00:00:00 2001 From: ibakshay Date: Thu, 9 Feb 2023 10:49:04 +0100 Subject: [PATCH 2/5] test --- dist/index.js | 4 +++- src/persistence/persistence.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 70b11dc6..b2244f8e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1904,6 +1904,7 @@ 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; + console.log(input.getSignedCommitMessage()); console.log(JSON.stringify(github_1.context.issue, null, 3)); claFileContent === null || claFileContent === void 0 ? void 0 : claFileContent.signedContributors.push(...reactedCommitters.newSigned); let contentString = JSON.stringify(claFileContent, null, 2); @@ -1917,13 +1918,14 @@ function updateFile(sha, claFileContent, reactedCommitters) { ? input .getSignedCommitMessage() .replace('$contributorName', github_1.context.actor) - .replace('$pullRequestNo', github_1.context.issue.number.toString()) + .replace('$pullRequestNo', pullRequestNo.toString()) .replace('$owner', github_1.context.issue.owner) .replace('$repo', github_1.context.issue.repo) : `@${github_1.context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, content: contentBinary, branch: input.getBranch() }); + console.log(input.getSignedCommitMessage()); }); } exports.updateFile = updateFile; diff --git a/src/persistence/persistence.ts b/src/persistence/persistence.ts index cbb63bea..5cea6fb9 100644 --- a/src/persistence/persistence.ts +++ b/src/persistence/persistence.ts @@ -44,6 +44,7 @@ export async function updateFile( isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient() const pullRequestNo = context.issue.number + console.log(input.getSignedCommitMessage()) console.log(JSON.stringify(context.issue, null, 3)) claFileContent?.signedContributors.push(...reactedCommitters.newSigned) let contentString = JSON.stringify(claFileContent, null, 2) @@ -57,13 +58,14 @@ export async function updateFile( ? input .getSignedCommitMessage() .replace('$contributorName', context.actor) - .replace('$pullRequestNo', context.issue.number.toString()) + .replace('$pullRequestNo', pullRequestNo.toString()) .replace('$owner', context.issue.owner) .replace('$repo', context.issue.repo) : `@${context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, content: contentBinary, branch: input.getBranch() }) + console.log(input.getSignedCommitMessage()) } function isRemoteRepoOrOrgConfigured(): boolean { From 8b079a84d5a9a800e511e98438ebd5321e604a3a Mon Sep 17 00:00:00 2001 From: ibakshay Date: Thu, 9 Feb 2023 10:50:59 +0100 Subject: [PATCH 3/5] test --- dist/index.js | 8 +++++++- src/persistence/persistence.ts | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index b2244f8e..4ce690db 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1925,7 +1925,13 @@ function updateFile(sha, claFileContent, reactedCommitters) { content: contentBinary, branch: input.getBranch() }); - console.log(input.getSignedCommitMessage()); + const test = input + .getSignedCommitMessage() + .replace('$contributorName', github_1.context.actor) + .replace('$pullRequestNo', pullRequestNo.toString()) + .replace('$owner', github_1.context.issue.owner) + .replace('$repo', github_1.context.issue.repo); + console.log(test); }); } exports.updateFile = updateFile; diff --git a/src/persistence/persistence.ts b/src/persistence/persistence.ts index 5cea6fb9..e00ac1fc 100644 --- a/src/persistence/persistence.ts +++ b/src/persistence/persistence.ts @@ -65,7 +65,13 @@ export async function updateFile( content: contentBinary, branch: input.getBranch() }) - console.log(input.getSignedCommitMessage()) + const test = input + .getSignedCommitMessage() + .replace('$contributorName', context.actor) + .replace('$pullRequestNo', pullRequestNo.toString()) + .replace('$owner', context.issue.owner) + .replace('$repo', context.issue.repo) + console.log(test) } function isRemoteRepoOrOrgConfigured(): boolean { From 7ae6ca3ee2ce1e274f9f8ca56edb56887aff7290 Mon Sep 17 00:00:00 2001 From: ibakshay Date: Thu, 9 Feb 2023 10:56:54 +0100 Subject: [PATCH 4/5] enhance commit message --- dist/index.js | 19 ++++++------------- src/persistence/persistence.ts | 20 +++++++------------- 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4ce690db..6ac87be9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1904,8 +1904,8 @@ 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; - console.log(input.getSignedCommitMessage()); - console.log(JSON.stringify(github_1.context.issue, null, 3)); + 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); let contentString = JSON.stringify(claFileContent, null, 2); let contentBinary = Buffer.from(contentString).toString('base64'); @@ -1918,20 +1918,13 @@ function updateFile(sha, claFileContent, reactedCommitters) { ? input .getSignedCommitMessage() .replace('$contributorName', github_1.context.actor) - .replace('$pullRequestNo', pullRequestNo.toString()) - .replace('$owner', github_1.context.issue.owner) - .replace('$repo', github_1.context.issue.repo) - : `@${github_1.context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, + // .replace('$pullRequestNo', pullRequestNo.toString()) + .replace('$owner', owner) + .replace('$repo', repo) + : `@${github_1.context.actor} has signed the CLA in ${owner}/${repo}#${pullRequestNo}`, content: contentBinary, branch: input.getBranch() }); - const test = input - .getSignedCommitMessage() - .replace('$contributorName', github_1.context.actor) - .replace('$pullRequestNo', pullRequestNo.toString()) - .replace('$owner', github_1.context.issue.owner) - .replace('$repo', github_1.context.issue.repo); - console.log(test); }); } exports.updateFile = updateFile; diff --git a/src/persistence/persistence.ts b/src/persistence/persistence.ts index e00ac1fc..f5a08e48 100644 --- a/src/persistence/persistence.ts +++ b/src/persistence/persistence.ts @@ -44,8 +44,9 @@ export async function updateFile( isRemoteRepoOrOrgConfigured() ? getPATOctokit() : getDefaultOctokitClient() const pullRequestNo = context.issue.number - console.log(input.getSignedCommitMessage()) - console.log(JSON.stringify(context.issue, null, 3)) + const owner = context.issue.owner + const repo = context.issue.repo + claFileContent?.signedContributors.push(...reactedCommitters.newSigned) let contentString = JSON.stringify(claFileContent, null, 2) let contentBinary = Buffer.from(contentString).toString('base64') @@ -58,20 +59,13 @@ export async function updateFile( ? input .getSignedCommitMessage() .replace('$contributorName', context.actor) - .replace('$pullRequestNo', pullRequestNo.toString()) - .replace('$owner', context.issue.owner) - .replace('$repo', context.issue.repo) - : `@${context.actor} has signed the CLA from Pull Request #${pullRequestNo}`, + // .replace('$pullRequestNo', pullRequestNo.toString()) + .replace('$owner', owner) + .replace('$repo', repo) + : `@${context.actor} has signed the CLA in ${owner}/${repo}#${pullRequestNo}`, content: contentBinary, branch: input.getBranch() }) - const test = input - .getSignedCommitMessage() - .replace('$contributorName', context.actor) - .replace('$pullRequestNo', pullRequestNo.toString()) - .replace('$owner', context.issue.owner) - .replace('$repo', context.issue.repo) - console.log(test) } function isRemoteRepoOrOrgConfigured(): boolean { From 0ce7444ce412f96aba3dae7226d8751b44e58ec5 Mon Sep 17 00:00:00 2001 From: ibakshay Date: Thu, 9 Feb 2023 11:38:45 +0100 Subject: [PATCH 5/5] fixes readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1382fae1..ac28f3c4 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ jobs: #remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository) #remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository) #create-file-commit-message: 'For example: Creating file for storing CLA Signatures' - #signed-commit-message: 'For example: $contributorName has signed the CLA' + #signed-commit-message: 'For example: $contributorName has signed the CLA in $owner/$repo#$pullRequestNo' #custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign' #custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA' #custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'