Improve handling of head branch in pull requests

This revision modifies the functionality to handle the head branch in pull requests. It allows for the head branch to be input manually, and provides clearer error messaging when working from a non-branch. Additionally, it updates the description for the base and head parameters in 'action.yml' for better understanding.
This commit is contained in:
Julien Fastré 2024-03-08 12:04:05 +01:00
parent 358b8d696b
commit f802f2b6eb
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 14 additions and 4 deletions

View File

@ -18,8 +18,11 @@ inputs:
description: 'A comma or newline separated list of assignees (GitHub usernames).'
base:
description: >
The pull request base branch.
The pull request base branch (the one into which the new code will be pushed).
required: true
head:
description: >
The pull request head branch (the one within the new code is developed).
outputs:
pull-request-number:
description: 'The pull request number'

13
main.go
View File

@ -44,14 +44,21 @@ func ParseActionConfig() (*CreatePrConfig, error) {
labels = append(labels, strings.TrimSpace(l))
}
if githubactions.GetInput("GITHUB_REF_TYPE") != "branch" {
return nil, fmt.Errorf("only branch can create a pull request: %v given", githubactions.GetInput("GITHUB_REF_TYPE"))
var head string
headRaw := githubactions.GetInput("head")
if headRaw == "" {
if githubactions.GetInput("GITHUB_REF_TYPE") != "branch" {
return nil, fmt.Errorf("set the \"head\" parameter or work from a branch: only branch can create a pull request: %v given as parameter GITHUB_REF_TYPE", githubactions.GetInput("GITHUB_REF_TYPE"))
}
head = githubactions.GetInput("GITHUB_REF_NAME")
} else {
head = headRaw
}
return &CreatePrConfig{
Org: ctx.RepositoryOwner,
Repo: rawRepo[1],
HeadBranch: githubactions.GetInput("GITHUB_REF_NAME"),
HeadBranch: head,
BaseBranch: base,
Title: title,
Body: body,