Skip to content

Commit

Permalink
tmp get labels from context?
Browse files Browse the repository at this point in the history
  • Loading branch information
simu committed Nov 3, 2023
1 parent d0ebf29 commit 79d2717
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
28 changes: 24 additions & 4 deletions __tests__/bump-labels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ describe('prBumpLabel', () => {
})

it('identifies bump:patch label', async () => {
getOctokitMock.mockImplementation(makePROctokitMock('bump:patch'))
//getOctokitMock.mockImplementation(makePROctokitMock('bump:patch'))
if (github.context.payload.pull_request) {
github.context.payload.pull_request['labels'] = [{ name: 'bump:patch' }]
}

await expect(bump_labels.prBumpLabel(bumpLabels)).resolves.toStrictEqual({
bump: 'patch' as ReleaseType,
Expand All @@ -110,7 +113,10 @@ describe('prBumpLabel', () => {
})

it('identifies bump:minor label', async () => {
getOctokitMock.mockImplementation(makePROctokitMock('bump:minor'))
//getOctokitMock.mockImplementation(makePROctokitMock('bump:minor'))
if (github.context.payload.pull_request) {
github.context.payload.pull_request.labels = [{ name: 'bump:minor' }]
}

await expect(bump_labels.prBumpLabel(bumpLabels)).resolves.toStrictEqual({
bump: 'minor' as ReleaseType,
Expand All @@ -119,7 +125,10 @@ describe('prBumpLabel', () => {
})

it('identifies bump:major label', async () => {
getOctokitMock.mockImplementation(makePROctokitMock('bump:major'))
//getOctokitMock.mockImplementation(makePROctokitMock('bump:major'))
if (github.context.payload.pull_request) {
github.context.payload.pull_request.labels = [{ name: 'bump:major' }]
}

await expect(bump_labels.prBumpLabel(bumpLabels)).resolves.toStrictEqual({
bump: 'major' as ReleaseType,
Expand All @@ -128,7 +137,10 @@ describe('prBumpLabel', () => {
})

it('logs a message when no bump labels are present', async () => {
getOctokitMock.mockImplementation(makePROctokitMock())
//getOctokitMock.mockImplementation(makePROctokitMock())
if (github.context.payload.pull_request) {
github.context.payload.pull_request.labels = []
}

await expect(bump_labels.prBumpLabel(bumpLabels)).resolves.toStrictEqual({
bump: null,
Expand All @@ -139,9 +151,17 @@ describe('prBumpLabel', () => {
})

it('logs a warning when multiple bump labels are present', async () => {
/*
getOctokitMock.mockImplementation(
makePROctokitMock('bump:patch', 'bump:minor')
)
*/
if (github.context.payload.pull_request) {
github.context.payload.pull_request.labels = [
{ name: 'bump:patch' },
{ name: 'bump:minor' }
]
}

await expect(bump_labels.prBumpLabel(bumpLabels)).resolves.toStrictEqual({
bump: null,
Expand Down
2 changes: 1 addition & 1 deletion badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion dist/index.js

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

9 changes: 8 additions & 1 deletion src/bump-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ interface BumpAction {
}

export async function prBumpLabel(b: BumpLabels): Promise<BumpAction> {
const prLabels = await getPRLabels()
if (!github.context.payload.pull_request) {
throw new Error(
`Action is running on a '${github.context.eventName}' event, only 'pull_request' events are supported`
)
}
const prLabels = github.context.payload.labels.map(
(lbl: { name: string }) => lbl.name
)
const bumpLabels = prLabels.filter(
(l: string) => l === b.patch || l === b.minor || l === b.major
)
Expand Down

0 comments on commit 79d2717

Please sign in to comment.