Skip to content

Commit

Permalink
Otterize CLA bot
Browse files Browse the repository at this point in the history
  • Loading branch information
tomergreenwald authored Oct 16, 2022
1 parent 04c9b2d commit aa0858c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/addEmptyCommit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function addEmptyCommit() {
if (context.payload.comment) {

//Do empty commit only when the contributor signs the CLA with the PR comment
if (context.payload.comment.body === 'I have read the CLA Document and I hereby sign the CLA') {
if (context.payload.comment.body === 'I have read and understood the CLA and hereby agree to its terms by making this Pull Request Comment.') {
try {
const message = input.getSignedCommitMessage() ?
input.getSignedCommitMessage().replace('$contributorName', contributorName) :
Expand Down
8 changes: 7 additions & 1 deletion src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ export default async function getCommitters(): Promise<CommittersDetails[]> {
})
response.repository.pullRequest.commits.edges.forEach(edge => {
const committer = extractUserFromCommit(edge.node.commit)
const userName = extractUserNameFromCommit(edge.node.commit)
const userEmail = extractEmailFromCommit(edge.node.commit)
let user = {
name: committer.login || committer.name,
userName: userName,
userEmail: userEmail,
id: committer.databaseId || '',
pullRequestNo: context.issue.number
}
Expand All @@ -74,4 +78,6 @@ export default async function getCommitters(): Promise<CommittersDetails[]> {
}

}
const extractUserFromCommit = (commit) => commit.author.user || commit.committer.user || commit.author || commit.committer
const extractUserFromCommit = (commit) => commit.author.user || commit.committer.user || commit.author || commit.committer
const extractUserNameFromCommit = (commit) => commit.author.name || commit.committer.name
const extractEmailFromCommit = (commit) => commit.author.email
2 changes: 2 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export interface CommentedCommitterMap {
}
export interface CommittersDetails {
name: string,
userName: string,
userEmail: string,
id: number,
pullRequestNo?: number,
created_at?: string,
Expand Down
12 changes: 9 additions & 3 deletions src/pullrequest/pullRequestCommentContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ function cla(signed: boolean, committerMap: CommitterMap): string {

}

let you = committersCount > 1 ? `you all` : `you`
let lineOne = (input.getCustomNotSignedPrComment() || `<br/>Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that $you sign our [Contributor License Agreement](${input.getPathToDocument()}) before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.<br/>`).replace('$you', you)

let lineOne = (input.getCustomNotSignedPrComment() || `<br/>Thank you for your submission -- we really appreciate it! Like many open-source projects, we ask that every contributor signs our [Contributor License Agreement (CLA)](${input.getPathToDocument()}) before we can accept their contribution. This is to protect your rights, ours, and those of future users of this software.<br/><br/>Here is the information GitHub has on the contributors of this Pull Request (who have not yet signed this CLA):`)
let missingUsersText = ""
committerMap.notSigned.forEach(function (entry) {
missingUsersText += `<br/>- GitHub handle: ${entry.name}<br/>- Name: ${entry.userName}<br/>- Email: ${entry.userEmail}<br/>`
})
missingUsersText += `<br/>To acknowledge that your information above is correct, that we may record it, and that you have read, understood, and agreed to this CLA, please sign the CLA by posting a Pull Request Comment below, containing the following exact text:`
let text = `**CLA Assistant Lite bot:** ${lineOne}
${missingUsersText}
- - -
${input.getCustomPrSignComment() || "I have read the CLA Document and I hereby sign the CLA"}
${input.getCustomPrSignComment() || "I have read and understood the CLA and hereby agree to its terms by making this Pull Request Comment."}
- - -
`

Expand Down
8 changes: 8 additions & 0 deletions src/pullrequest/signatureComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ export default async function signatureWithPRComment(committerMap: CommitterMap,
let listOfPRComments = [] as CommittersDetails[]
let filteredListOfPRComments = [] as CommittersDetails[]

let hashedCommitters = committers.reduce(function(map, obj) {
map[obj.id] = obj;
return map;
}, {});


prResponse?.data.map((prComment) => {
listOfPRComments.push({
name: prComment.user.login,
userName: hashedCommitters[prComment.user.id.toString()]?.userName,
userEmail: hashedCommitters[prComment.user.id.toString()]?.userEmail,
id: prComment.user.id,
comment_id: prComment.id,
body: prComment.body.trim().toLowerCase(),
Expand Down

0 comments on commit aa0858c

Please sign in to comment.