Skip to content

Commit 5fdd97e

Browse files
authored
🐛 fix: add more log and fix comment filter (#13)
1 parent 5e32441 commit 5fdd97e

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

.github/workflows/example-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
},
4444
{
4545
"type": "commented",
46-
"comment-pattern": [".+/bypass example.+", ".+/bypass all.+"],
46+
"comment-pattern": [".*/bypass example.*", ".*/bypass all.*"],
4747
"username": ["SigureMo"]
4848
},
4949
{

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
},
9393
{
9494
"type": "commented",
95-
"comment-pattern": [".+/bypass example.+", ".+/bypass all.+"],
95+
"comment-pattern": [".*/bypass example.*", ".*/bypass all.*"],
9696
"username": ["SigureMo"]
9797
},
9898
{

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/composite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function isNotComposite<T>(composite: Composite<T>): composite is NotComposite<T
2828
return (composite as NotComposite<T>).not !== undefined
2929
}
3030

31-
function resolveAnyCompositeHighterOrder<T>(
31+
function resolveAnyComposite<T>(
3232
predicate: (value: T) => boolean
3333
): (composite: AnyComposite<T>) => boolean {
3434
return (composite: AnyComposite<T>) => composite.any.some(predicate)
@@ -54,7 +54,7 @@ export function resolveComposite<T>(
5454
}
5555
return (composite: Composite<T>) => {
5656
if (isAnyComposite(composite)) {
57-
return resolveAnyCompositeHighterOrder(predicateForComposite)(composite)
57+
return resolveAnyComposite(predicateForComposite)(composite)
5858
} else if (isAllComposite(composite)) {
5959
return resolveAllComposite(predicateForComposite)(composite)
6060
} else if (isNotComposite(composite)) {

src/main.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function parseRuleRawObjectFromInput(): any {
2727
case CommentRule.type:
2828
return {
2929
type: CommentRule.type,
30-
'message-pattern': parseArrayInput(core.getInput('message-pattern'), '|'),
30+
'comment-pattern': parseArrayInput(core.getInput('comment-pattern'), '|'),
3131
username: parseArrayInput(core.getInput('username'), '|'),
3232
'user-team': parseArrayInput(core.getInput('user-team'), '|'),
3333
}
@@ -73,10 +73,13 @@ function checkNonPullRequestEvent() {
7373
*/
7474
export async function run(): Promise<void> {
7575
try {
76-
if (checkNonPullRequestEvent()) return
76+
if (checkNonPullRequestEvent()) {
77+
core.info('Non-pull-request event, skipping the check')
78+
return
79+
}
7780
const githubToken: string = core.getInput('github-token')
7881
const rawRule = parseRuleRawObjectFromInput()
79-
core.info(`rawRule: ${JSON.stringify(rawRule)}`)
82+
core.debug(`rawRule: ${JSON.stringify(rawRule)}`)
8083

8184
async function check(value: any): Promise<boolean> {
8285
const bypassChecker = new ByPassCheckerBuilder()
@@ -88,7 +91,7 @@ export async function run(): Promise<void> {
8891
}
8992

9093
const result = await resolveCompositeAsync(check)(rawRule)
91-
core.info(`check result: ${result}`)
94+
core.info(`Setting can-skip output to ${result}`)
9295
// Set outputs for other workflow steps to use
9396
core.setOutput('can-skip', result)
9497
} catch (error) {

src/rules/comment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ function compilePattern(pattern: string): RegExp {
1515

1616
export class CommentRule extends AbstractRule {
1717
public static type: string = 'commented'
18-
public messagePatterns: RegExp[]
18+
public commentPatterns: RegExp[]
1919
public userNames: string[]
2020
public userTeams: string[]
2121
constructor(
22-
messagePattern: string | string[],
22+
commentPattern: string | string[],
2323
userName: string | string[] | undefined,
2424
userTeam: string | string[] | undefined
2525
) {
2626
super()
27-
this.messagePatterns = resolveOneOrMoreOption(messagePattern).map(compilePattern)
27+
this.commentPatterns = resolveOneOrMoreOption(commentPattern).map(compilePattern)
2828
this.userNames = resolveMaybeOneOrMoreOption(userName)
2929
this.userTeams = resolveMaybeOneOrMoreOption(userTeam)
3030
}
@@ -52,7 +52,7 @@ export class CommentRule extends AbstractRule {
5252
return { content: comment.body, actor: comment.user.login }
5353
})
5454
.filter((comment): comment is CommentWithActor => comment !== undefined)
55-
.filter((comment) => this.messagePatterns.some((pattern) => pattern.test(comment.content)))
55+
.filter((comment) => this.commentPatterns.some((pattern) => pattern.test(comment.content)))
5656
const IsValidComment = async (comment: CommentWithActor): Promise<Boolean> => {
5757
const currentCommentUserName = comment.actor
5858
return await isValidUser(
@@ -64,13 +64,13 @@ export class CommentRule extends AbstractRule {
6464
)
6565
}
6666
core.debug(`allCommentWithActors: ${JSON.stringify(allCommentWithActors)}`)
67-
core.debug(`messagePatterns: ${JSON.stringify(this.messagePatterns)}`)
67+
core.debug(`messagePatterns: ${JSON.stringify(this.commentPatterns)}`)
6868
return await Promise.all(allCommentWithActors.map(IsValidComment)).then((results) =>
6969
results.some((result) => result)
7070
)
7171
}
7272

7373
public static fromObject(obj: any): CommentRule {
74-
return new CommentRule(obj['message-pattern'], obj['username'], obj['user-team'])
74+
return new CommentRule(obj['comment-pattern'], obj['username'], obj['user-team'])
7575
}
7676
}

0 commit comments

Comments
 (0)