Skip to content

Commit

Permalink
refactoring 🚧
Browse files Browse the repository at this point in the history
  • Loading branch information
ibakshay committed May 7, 2021
1 parent cb8fa13 commit 655a7dc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ export interface CommitterMap {
notSigned: CommittersDetails[],
unknown: CommittersDetails[]
}

export interface ReactedCommitterMap {
newSigned: CommittersDetails[],
onlyCommitters?: CommittersDetails[],
allSignedFlag: boolean
}

export interface CommentedCommitterMap {
newSigned: CommittersDetails[],
onlyCommitters?: CommittersDetails[],
allSignedFlag: boolean
}

export interface CommittersDetails {
name: string,
id: number,
Expand All @@ -26,12 +23,10 @@ export interface CommittersDetails {
body?: string,
repoId?: string
}

export interface LabelName {
current_name: string,
name: string
}

export interface CommittersCommentDetails {
name: string,
id: number,
Expand All @@ -40,7 +35,6 @@ export interface CommittersCommentDetails {
created_at: string,
updated_at: string
}

export interface ClafileContentAndSha {
claFileContent: any,
sha: string
Expand Down
19 changes: 9 additions & 10 deletions src/pullrequest/pullRequestComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ export default async function prCommentSetup(committerMap: CommitterMap, committ
}

// reacted committers are contributors who have newly signed by posting the Pull Request comment
const reactedCommitters: ReactedCommitterMap = (await signatureWithPRComment(committerMap, committers)) as ReactedCommitterMap
if (reactedCommitters) {
if (reactedCommitters.onlyCommitters) {
const reactedCommitters = await signatureWithPRComment(committerMap, committers)
if (reactedCommitters?.onlyCommitters) {
reactedCommitters.allSignedFlag = prepareAllSignedCommitters(committerMap, reactedCommitters.onlyCommitters, committers)
}
}
committerMap = prepareCommiterMap(committerMap, reactedCommitters)
await updateComment(reactedCommitters.allSignedFlag, committerMap, claBotComment)
Expand All @@ -61,7 +59,7 @@ async function updateComment(signed: boolean, committerMap: CommitterMap, claBot
repo: context.repo.repo,
comment_id: claBotComment.id,
body: commentContent(signed, committerMap)
}).catch(error => { throw new Error(`Error occured when getting all the comments of the pull request: ${error.message}`) })
}).catch(error => { throw new Error(`Error occured when updating the pull request comment: ${error.message}`) })
}

async function getComment() {
Expand Down Expand Up @@ -95,12 +93,13 @@ function prepareCommiterMap(committerMap: CommitterMap, reactedCommitters) {
function prepareAllSignedCommitters(committerMap: CommitterMap, signedInPrCommitters: CommittersDetails[], committers: CommittersDetails[]): boolean {
let allSignedCommitters = [] as CommittersDetails[]
/*
1) already signed committers in the file 2) signed committers in the PR comment
*/
let ids = new Set(signedInPrCommitters.map(committer => committer.id))
* 1) already signed committers in the file 2) signed committers in the PR comment
*/
const ids = new Set(signedInPrCommitters.map(committer => committer.id))
allSignedCommitters = [...signedInPrCommitters, ...committerMap.signed!.filter(signedCommitter => !ids.has(signedCommitter.id))]

//checking if all the unsigned committers have reacted to the PR comment (this is needed for changing the content of the PR comment to "All committers have signed the CLA")
/*
* checking if all the unsigned committers have reacted to the PR comment (this is needed for changing the content of the PR comment to "All committers have signed the CLA")
*/
let allSignedFlag: boolean = committers.every(committer => allSignedCommitters.some(reactedCommitter => committer.id === reactedCommitter.id))
return allSignedFlag
}
Expand Down
37 changes: 18 additions & 19 deletions src/pullrequest/signatureComment.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { octokit } from '../octokit'
import { context } from '@actions/github'
import { CommitterMap, CommittersDetails, CommentedCommitterMap } from '../interfaces'
import { CommitterMap, CommittersDetails, ReactedCommitterMap } from '../interfaces'
import { getUseDcoFlag, getCustomPrSignComment } from '../shared/getInputs'

import * as core from '@actions/core'

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

let repoId = context.payload.repository!.id
let commentedCommitterMap = {} as CommentedCommitterMap
// let commentedCommitterMap = {} as CommentedCommitterMap
let prResponse = await octokit.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down Expand Up @@ -36,24 +36,23 @@ export default async function signatureWithPRComment(committerMap: CommitterMap,
for (var i = 0; i < filteredListOfPRComments.length; i++) {
delete filteredListOfPRComments[i].body
}
//checking if the reacted committers are not the signed committers(not in the storage file) and filtering only the unsigned committers
commentedCommitterMap.newSigned = filteredListOfPRComments.filter(commentedCommitter => committerMap.notSigned!.some(notSignedCommitter => commentedCommitter.id === notSignedCommitter.id))
// if (context.eventName === 'issue_comment') {
// //Do empty commit only when the contributor signs the CLA with the PR comment and then check if the comment is from the newsigned contributor
// if (input.getEmptyCommitFlag() == 'true') {
// if (commentedCommitterMap.newSigned.some(contributor => contributor.id === context?.payload?.comment?.user.id)) {
// await addEmptyCommit()
// }
// }
// }

// if (blockChainFlag == 'true' && commentedCommitterMap.newSigned) {
// await blockChainWebhook(commentedCommitterMap.newSigned)
// }
/*
*checking if the reacted committers are not the signed committers(not in the storage file) and filtering only the unsigned committers
*/
const newSigned = filteredListOfPRComments.filter(commentedCommitter => committerMap.notSigned!.some(notSignedCommitter => commentedCommitter.id === notSignedCommitter.id))
// commentedCommitterMap.newSigned = filteredListOfPRComments.filter(commentedCommitter => committerMap.notSigned!.some(notSignedCommitter => commentedCommitter.id === notSignedCommitter.id))

/*
* checking if the commented users are only the contributors who has committed in the same PR (This is needed for the PR Comment and changing the status to success when all the contributors has reacted to the PR)
*/
const onlyCommitters = committers.filter(committer => filteredListOfPRComments.some(commentedCommitter => committer.id == commentedCommitter.id))
// commentedCommitterMap.onlyCommitters = committers.filter(committer => filteredListOfPRComments.some(commentedCommitter => committer.id == commentedCommitter.id))
let commentedCommitterMap: ReactedCommitterMap = {
newSigned,
onlyCommitters,
allSignedFlag: false
}

//checking if the commented users are only the contributors who has committed in the same PR (This is needed for the PR Comment and changing the status to success when all the contributors has reacted to the PR)
commentedCommitterMap.onlyCommitters = committers.filter(committer => filteredListOfPRComments.some(commentedCommitter => committer.id == commentedCommitter.id))
return commentedCommitterMap

}
Expand Down
2 changes: 1 addition & 1 deletion src/setupClaCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function setupClaCheck() {
console.log('committerMap :>> ', committerMap)

try {
const reactedCommitters = await prCommentSetup(committerMap, committers) as ReactedCommitterMap
const reactedCommitters = await prCommentSetup(committerMap, committers) as ReactedCommitterMap

// if (signed) {
// core.info(`All committers have signed the CLA`)
Expand Down

0 comments on commit 655a7dc

Please sign in to comment.