Skip to content

Commit

Permalink
Merge pull request #136 from akashivskyy/lowercase-labels
Browse files Browse the repository at this point in the history
Perform case-insensitive comparison
  • Loading branch information
mattcosta7 committed Jun 22, 2022
2 parents aeb80ee + a1e8057 commit 7334092
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
43 changes: 43 additions & 0 deletions __tests__/add-to-project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,49 @@ describe('addToProject', () => {
projectNumber: 1
})
})

test('compares labels case-insensitively', async () => {
mockGetInput({
'project-url': 'https://github.com/orgs/github/projects/1',
'github-token': 'gh_token',
labeled: 'FOO, Bar, baz',
'label-operator': 'AND'
})

github.context.payload = {
issue: {
number: 1,
labels: [{name: 'foo'}, {name: 'BAR'}, {name: 'baz'}]
}
}

mockGraphQL(
{
test: /getProject/,
return: {
organization: {
projectNext: {
id: 'project-next-id'
}
}
}
},
{
test: /addProjectNextItem/,
return: {
addProjectNextItem: {
projectNextItem: {
id: 'project-next-item-id'
}
}
}
}
)

await addToProject()

expect(outputs.itemId).toEqual('project-next-item-id')
})
})

describe('mustGetOwnerTypeQuery', () => {
Expand Down
4 changes: 2 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/add-to-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ export async function addToProject(): Promise<void> {
core
.getInput('labeled')
.split(',')
.map(l => l.trim())
.map(l => l.trim().toLowerCase())
.filter(l => l.length > 0) ?? []
const labelOperator = core.getInput('label-operator').trim().toLocaleLowerCase()

const octokit = github.getOctokit(ghToken)
const urlMatch = projectUrl.match(urlParse)
const issue = github.context.payload.issue ?? github.context.payload.pull_request
const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name)
const issueLabels: string[] = (issue?.labels ?? []).map((l: {name: string}) => l.name.toLowerCase())

// Ensure the issue matches our `labeled` filter based on the label-operator.
if (labelOperator === 'and') {
Expand Down

0 comments on commit 7334092

Please sign in to comment.