Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not tips when partner not signed #8

Merged
merged 1 commit into from
Dec 7, 2022
Merged
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: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/pullrequest/partnerPullRequestCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ const yaml = require('js-yaml');

export const partnerEmailSuffix = new Set<string>()
export const partnerAllMemberIds= new Map<string, string>()
let partnerSigned

export async function checkPartnerPullRequestUserIsInOrg() {

// cache status, scripts onely run in a short time(a few seconds), no need to refresh it.
if (partnerSigned !== undefined) {
return partnerSigned
}

let octokit

if (isAppPrivateKeyPresent !== undefined && isAppPrivateKeyPresent()) {
Expand All @@ -32,6 +38,8 @@ export async function checkPartnerPullRequestUserIsInOrg() {

core.debug(data?.user?.login + " is in " + partnerAllMemberIds.get(userid))

partnerSigned = partnerAllMemberIds.has(userid)

return partnerAllMemberIds.has(userid)
}

Expand Down
17 changes: 8 additions & 9 deletions src/pullrequest/pullRequestComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { checkPartnerPullRequestUserIsInOrg } from './partnerPullRequestCheck'

export default async function prCommentSetup(committerMap: CommitterMap, committers: CommittersDetails[]) {
const signed = committerMap?.notSigned && committerMap?.notSigned.length === 0
const partnerSigned = committerMap?.partner === undefined || committerMap?.partner.length === 0 || (checkPartnerPullRequestUserIsInOrg !== undefined && await checkPartnerPullRequestUserIsInOrg())

try {
const claBotComment = await getComment()
if (!claBotComment && !signed) {
return createComment(signed, committerMap)
if (!claBotComment && !(signed && partnerSigned)) {
return createComment(signed, partnerSigned, committerMap)
} else if (claBotComment?.id) {
if (signed) {
await updateComment(signed, committerMap, claBotComment)
if (signed || partnerSigned) {
await updateComment(signed, partnerSigned, committerMap, claBotComment)
}

// reacted committers are contributors who have newly signed by posting the Pull Request comment
Expand All @@ -27,7 +28,7 @@ export default async function prCommentSetup(committerMap: CommitterMap, committ
reactedCommitters.allSignedFlag = prepareAllSignedCommitters(committerMap, reactedCommitters.onlyCommitters, committers)
}
committerMap = prepareCommiterMap(committerMap, reactedCommitters)
await updateComment(reactedCommitters.allSignedFlag, committerMap, claBotComment)
await updateComment(reactedCommitters.allSignedFlag, partnerSigned, committerMap, claBotComment)
return reactedCommitters
}
} catch (error) {
Expand All @@ -36,8 +37,7 @@ export default async function prCommentSetup(committerMap: CommitterMap, committ
}
}

async function createComment(signed: boolean, committerMap: CommitterMap): Promise<void> {
const partnerSigned = committerMap?.notSigned === undefined || committerMap?.partner.length === 0 || (checkPartnerPullRequestUserIsInOrg !== undefined && await checkPartnerPullRequestUserIsInOrg())
async function createComment(signed: boolean, partnerSigned: boolean, committerMap: CommitterMap): Promise<void> {
await octokit.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -46,8 +46,7 @@ async function createComment(signed: boolean, committerMap: CommitterMap): Promi
}).catch(error => { throw new Error(`Error occured when creating a pull request comment: ${error.message}`) })
}

async function updateComment(signed: boolean, committerMap: CommitterMap, claBotComment: any): Promise<void> {
const partnerSigned = committerMap?.notSigned === undefined || committerMap?.partner.length === 0 || (checkPartnerPullRequestUserIsInOrg !== undefined && await checkPartnerPullRequestUserIsInOrg())
async function updateComment(signed: boolean, partnerSigned: boolean, committerMap: CommitterMap, claBotComment: any): Promise<void> {
await octokit.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
Expand Down