Skip to content

Commit

Permalink
feat: inherit assignee allowing override input (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorhugods authored Apr 29, 2024
1 parent 250f277 commit b0731e3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inputs:
pr-assignee:
description:
'(optional) User ID to be assigned to the created PR. Will use the
author of the original PR by default'
assignee of the original PR by default'
required: false
default: ''
pr-labels:
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.
25 changes: 21 additions & 4 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.

10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as core from '@actions/core'
import * as github from '@actions/github'
import { Label, PullRequest } from '@octokit/webhooks-types'
import { addLabels, createPullRequest } from './pr'
import { addAssignee, addLabels, createPullRequest } from './pr'
import {
cherryPickChangesToNewBranch,
configureGitUser,
Expand Down Expand Up @@ -37,9 +37,9 @@ export async function run(): Promise<void> {
const githubToken = core.getInput('pr-creator-token')
const submoduleName = core.getInput('submodule-name')
let prAssignee = core.getInput('pr-assignee')
if (prAssignee === '') {
// Use the author of the original PR as the assignee of the cherry-pick
prAssignee = mergedPR.user.login
if (prAssignee === '' && mergedPR.assignee != null) {
// Use the assignee of the original PR as the assignee of the cherry-pick
prAssignee = mergedPR.assignee.login
}
const labelsInput = core.getInput('pr-labels')
let addedLabels: string[] = []
Expand Down Expand Up @@ -112,6 +112,8 @@ export async function run(): Promise<void> {
inheritedLabels.concat(addedLabels)
)

await addAssignee(githubToken, resultPrNumber, prAssignee)

core.setOutput('pr-number', resultPrNumber)
} catch (error) {
// Fail the workflow run if an error occurs
Expand Down
20 changes: 20 additions & 0 deletions src/pr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,23 @@ export async function addLabels(
labels: labelsToAdd
})
}

export async function addAssignee(
githubToken: string,
issueNumber: number,
assigneeUserName: string
): Promise<void> {
if (assigneeUserName.length === 0) {
console.info('Skipping addition of assignee, as passed value is empty')
return
}
const octokit = github.getOctokit(githubToken)
const repoOwner = github.context.repo.owner
const repoName = github.context.repo.repo
await octokit.rest.issues.addAssignees({
owner: repoOwner,
repo: repoName,
issue_number: issueNumber,
assignees: [assigneeUserName]
})
}

0 comments on commit b0731e3

Please sign in to comment.