Skip to content

Commit

Permalink
Fix handling of owner/repository to support GitHub Actions
Browse files Browse the repository at this point in the history
Fix the handling of owner/repository input as so to support the
github.repository context which is provided for GitHub Actions in the
runner (separate owner and repo values are not provided and string
manipulation is not easy inside Actions).
  • Loading branch information
jonathanio committed May 29, 2023
1 parent f3fcab8 commit 77317bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ runs:
GITHUB_TOKEN: ${{ github.token }}
run: |-
${{ github.action_path }}/bin/pull-requester run \
--repository=${{ github.repository }} \
--number=${{ github.event.pull_request.number }} \
--title-minimum=${{ inputs.title-minimum }} \
--label-prefixes=${{ inputs.label-prefixes }}
--label-prefixes-any=${{ inputs.label-prefixes-any }}
Expand Down
11 changes: 6 additions & 5 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"strings"

"github.com/n3tuk/action-pull-requester/internal/action"
"github.com/n3tuk/action-pull-requester/internal/github"
Expand All @@ -10,7 +11,6 @@ import (
)

var (
owner string
repository string
number int

Expand All @@ -29,10 +29,9 @@ var (
)

func init() {
runCmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "Only show what actions would be taken")
runCmd.Flags().StringVarP(&owner, "owner", "o", "n3tuk", "The owner of the repository to check")
runCmd.Flags().StringVarP(&repository, "repository", "r", "action-pull-requester", "The name of the repository to check")
runCmd.Flags().StringVarP(&repository, "repository", "r", "n3tuk/action-pull-requester", "The name of the repository to check")
runCmd.Flags().IntVar(&number, "number", 0, "The number of the pull request to check")
runCmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "Only show what actions would be taken")
runCmd.Flags().IntVar(&titleMinimum, "title-minimum", titleMinimum, "The minimum number of characters a title should contain")
runCmd.Flags().StringVar(&labelPrefixes, "label-prefixes", "", "A comma-separated list of label prefixes to check for on a pull request")
runCmd.Flags().BoolVar(&labelPrefixesAny, "label-prefixes-any", false, "Set that any label prefix can match to pass, rather than all")
Expand All @@ -46,7 +45,9 @@ func RunChecks(cmd *cobra.Command, args []string) error {
LabelPrefixesAny: labelPrefixesAny,
}

pr, err := github.NewPullRequest(logger, owner, repository, number)
repo := strings.Split(repository, "/")

pr, err := github.NewPullRequest(logger, repo[0], repo[1], number)
if err != nil {
return fmt.Errorf("failed to fetch the pull request: %w", err)
}
Expand Down

0 comments on commit 77317bf

Please sign in to comment.