Skip to content

Commit

Permalink
Repositories can be a list
Browse files Browse the repository at this point in the history
  • Loading branch information
Zharktas committed Apr 11, 2024
1 parent e69df6c commit bdb2d16
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 43 deletions.
32 changes: 27 additions & 5 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('action', () => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'repository':
return 'vrk-kpa/fetch-open-prs-action'
return 'vrk-kpa/fetch-open-prs'
case 'ignored_users':
return '["first_ignore", "second_ignore"]'
default:
Expand All @@ -140,10 +140,9 @@ describe('action', () => {
await main.run()
expect(runMock).toHaveReturned()

expect(debugMock).toHaveBeenNthCalledWith(1, 'owner: vrk-kpa')
expect(debugMock).toHaveBeenNthCalledWith(2, 'repo: fetch-open-prs-action')

expect(debugMock).toHaveBeenNthCalledWith(3, 'Ignored users length: 2')
expect(debugMock).toHaveBeenNthCalledWith(1, 'Ignored users length: 2')
expect(debugMock).toHaveBeenNthCalledWith(2, 'owner: vrk-kpa')
expect(debugMock).toHaveBeenNthCalledWith(3, 'repo: fetch-open-prs')

expect(setOutputMock).toHaveBeenNthCalledWith(
1,
Expand Down Expand Up @@ -188,4 +187,27 @@ describe('action', () => {
expect.stringContaining('* [some title](http://example.com) by some_user')
)
})

it('Repository could be a list', async () => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'repository':
return '["vrk-kpa/fetch-open-prs", "vrk-kpa/some-other-repo"]'
default:
return ''
}
})

await main.run()
expect(runMock).toHaveReturned()

expect(debugMock).toHaveBeenNthCalledWith(1, 'owner: vrk-kpa')
expect(debugMock).toHaveBeenNthCalledWith(2, 'repo: fetch-open-prs')
expect(debugMock).toHaveBeenNthCalledWith(3, 'owner: vrk-kpa')
expect(debugMock).toHaveBeenNthCalledWith(4, 'repo: some-other-repo')

expect(setOutputMock.mock.calls[0][1]).toHaveLength(6)

expect(errorMock).not.toHaveBeenCalled()
})
})
45 changes: 27 additions & 18 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.

48 changes: 29 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export async function run(): Promise<void> {
const token = core.getInput('token')
const octokit = github.getOctokit(token)
const repository = core.getInput('repository')
const [owner, repo] = repository.split('/')

core.debug(`owner: ${owner}`)
core.debug(`repo: ${repo}`)

const prList = await octokit.rest.pulls.list({
owner,
repo
})
let repositories = []
try {
repositories = JSON.parse(repository)
} catch (err) {
repositories = [repository]
}

const ignored_users = core.getInput('ignored_users')

Expand All @@ -35,18 +33,30 @@ export async function run(): Promise<void> {
created_at: string
}[] = []

for (const pr of prList.data) {
const parsedPr = {
url: pr['html_url'],
title: pr['title'],
user: '',
created_at: pr['created_at']
}
for (let r of repositories) {

Check failure on line 36 in src/main.ts

View workflow job for this annotation

GitHub Actions / TypeScript Tests

'r' is never reassigned. Use 'const' instead

Check failure on line 36 in src/main.ts

View workflow job for this annotation

GitHub Actions / Lint Codebase

'r' is never reassigned. Use 'const' instead
const [owner, repo] = r.split('/')

core.debug(`owner: ${owner}`)
core.debug(`repo: ${repo}`)

const prList = await octokit.rest.pulls.list({
owner,
repo
})

for (const pr of prList.data) {
const parsedPr = {
url: pr['html_url'],
title: pr['title'],
user: '',
created_at: pr['created_at']
}

if (pr['user'] && !ignored_users_list.includes(pr['user']['login'])) {
parsedPr['user'] = pr['user']['login']
if (!pr['draft']) {
parsedPrList.push(parsedPr)
if (pr['user'] && !ignored_users_list.includes(pr['user']['login'])) {
parsedPr['user'] = pr['user']['login']
if (!pr['draft']) {
parsedPrList.push(parsedPr)
}
}
}
}
Expand Down

0 comments on commit bdb2d16

Please sign in to comment.