Skip to content

Commit

Permalink
Merge pull request #18 from nekonenene/develop
Browse files Browse the repository at this point in the history
Release 2021-09-13 02:45
  • Loading branch information
nekonenene authored Sep 12, 2021
2 parents 01185a0 + c59762f commit e6dddfc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ First, you need to get GitHub API Token to control your repository, please see [
### Example

```sh
gh-release-pr-generator --token 123456789abcd123456789abcd --repo-owner nekonenene --repo-name my-repository-name --dev-branch staging --prod-branch production
gh-release-pr-generator --token 123456789abcd123456789abcd --repo-owner nekonenene --repo-name my-repository-name --head-branch staging --base-branch production
```

### Parameters
Expand All @@ -47,8 +47,8 @@ gh-release-pr-generator --help
|-token| GitHub API Token | YES |
|-repo-owner| Repository owner name | YES |
|-repo-name| Repository name | YES |
|-prod-branch| Production branch name (default: `main`) | |
|-dev-branch| Development branch name (default: `develop`) | |
|-base-branch<br>(-prod-branch)| Production branch name (default: `main`) | |
|-head-branch<br>(-dev-branch)| Development branch name (default: `develop`) | |
|-template-path| PATH of the [template file](#template-file) | |
|-limit| Limit number of fetching pull requests (default: `100`) | |
|-enterprise-url| URL of GitHub Enterprise (ex. https://github.your.domain ) | |
Expand Down
2 changes: 1 addition & 1 deletion cmd/constants.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

const (
ProductionBranchNameDefault = "main"
BaseBranchNameDefault = "main"
DevelopmentBranchNameDefault = "develop"
PerPageDefault = 100
FirstPageNumberOfGitHubAPI = 1
Expand Down
2 changes: 1 addition & 1 deletion cmd/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func Exec() {

// Exit because GitHub API would refuse to create new pull request when no differences between branches
if len(diffCommitIDs) == 0 {
fmt.Printf("No differences between %s and %s branches\n", params.DevelopmentBranchName, params.ProductionBranchName)
fmt.Printf("No differences between %s and %s branches\n", params.DevelopmentBranchName, params.BaseBranchName)
return
}

Expand Down
9 changes: 5 additions & 4 deletions cmd/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"context"
"fmt"

"github.com/google/go-github/v34/github"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -39,7 +40,7 @@ func FetchDiffCommitIDs() ([]string, error) {
ctx,
params.RepositoryOwner,
params.RepositoryName,
params.ProductionBranchName,
params.BaseBranchName,
params.DevelopmentBranchName,
)
if err != nil {
Expand Down Expand Up @@ -102,8 +103,8 @@ func CreateOrUpdatePullRequest(title string, body string) (*github.PullRequest,
isCreated := false

releasePullRequests, _, err := githubClient.PullRequests.List(ctx, params.RepositoryOwner, params.RepositoryName, &github.PullRequestListOptions{
Head: params.DevelopmentBranchName,
Base: params.ProductionBranchName,
Head: fmt.Sprintf("%s:%s", params.RepositoryOwner, params.DevelopmentBranchName),
Base: params.BaseBranchName,
State: "open",
})
if err != nil {
Expand All @@ -124,7 +125,7 @@ func createPullRequest(title string, body string) (*github.PullRequest, error) {
Title: &title,
Body: &body,
Head: &params.DevelopmentBranchName,
Base: &params.ProductionBranchName,
Base: &params.BaseBranchName,
})

return newPullRequest, err
Expand Down
8 changes: 5 additions & 3 deletions cmd/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type parameters struct {
GitHubAPIToken string
RepositoryOwner string
RepositoryName string
ProductionBranchName string
BaseBranchName string
DevelopmentBranchName string
TemplatePath string
FetchPullRequestsLimit int
Expand All @@ -22,8 +22,10 @@ func ParseParameters() {
flag.StringVar(&params.GitHubAPIToken, "token", "", "[Required] GitHub API Token")
flag.StringVar(&params.RepositoryOwner, "repo-owner", "", "[Required] Repository owner")
flag.StringVar(&params.RepositoryName, "repo-name", "", "[Required] Repository name")
flag.StringVar(&params.ProductionBranchName, "prod-branch", ProductionBranchNameDefault, "[Opiton] production branch name")
flag.StringVar(&params.DevelopmentBranchName, "dev-branch", DevelopmentBranchNameDefault, "[Opiton] development branch name")
flag.StringVar(&params.BaseBranchName, "base-branch", BaseBranchNameDefault, "[Opiton] base branch name")
flag.StringVar(&params.BaseBranchName, "prod-branch", BaseBranchNameDefault, "[Opiton] alias of \"base-branch\"")
flag.StringVar(&params.DevelopmentBranchName, "head-branch", DevelopmentBranchNameDefault, "[Opiton] head branch (development branch) name")
flag.StringVar(&params.DevelopmentBranchName, "dev-branch", DevelopmentBranchNameDefault, "[Opiton] alias of \"head-branch\"")
flag.StringVar(&params.TemplatePath, "template-path", "", "[Opiton] template path for customizing the title and the body of the release pull request")
flag.IntVar(&params.FetchPullRequestsLimit, "limit", FetchPullRequestsLimitDefault, "[Opiton] limit number of fetching pull requests")
flag.StringVar(&params.EnterpriseURL, "enterprise-url", "", "[Opiton] URL of GitHub Enterprise (ex. https://github.your.domain )")
Expand Down

0 comments on commit e6dddfc

Please sign in to comment.