Skip to content

Commit

Permalink
Fixes for creating PR
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Jul 23, 2023
1 parent 8fcecab commit c3b9d6f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Let's configure GitHub backend for our repository:
And Jira backend for our issues:

```bash
➜ issuectl config backend add --jira-host https://my-org.atlassian.net/jira/ --jira-token "${JIRA_API_TOKEN}" --jira-username "${JIRA_USERNAME}" my-org-jira jira
➜ issuectl config backend add --jira-host https://my-org.atlassian.net/ --jira-token "${JIRA_API_TOKEN}" --jira-username "${JIRA_USERNAME}" my-org-jira jira
```

### Git Users
Expand Down
2 changes: 1 addition & 1 deletion cmd/issuectl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func initRepoAddCommand(rootCmd *cobra.Command) {
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 3 || len(args) > 3 {
return errors.New("you must provide exactly 3 arguments - owner, name and url of repository")
return errors.New("you must avide exactly 3 arguments - owner, name and url of repository")
}
return nil
},
Expand Down
6 changes: 1 addition & 5 deletions cmd/issuectl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ func MergeConfigWithOverwrites(conf issuectl.IssuectlConfig, overwrites *CLIOver
overwriteProfile.IssueBackend = issuectl.BackendConfigName(overwrites.IssueBackend)
}
if overwrites.Repos != nil {
repos := []issuectl.RepoConfigName{}

for _, repoName := range overwrites.Repos {
repos = append(repos, issuectl.RepoConfigName(repoName))
overwriteProfile.Repositories = append(overwriteProfile.Repositories, issuectl.RepoConfigName(repoName))
}

overwriteProfile.Repositories = repos
}

if err := conf.UpdateProfile(overwriteProfile); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions pkg/backend_jira.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ func NewJiraClient(email, apiToken, baseURL string) *Jira {
}

func (j *Jira) GetIssue(owner string, repo RepoConfigName, issueID IssueID) (interface{}, error) {
issue, _, err := j.client.Issue.Get(string(issueID), nil)
issues, _, err := j.client.Issue.Search("", &jira.SearchOptions{})
if err != nil {
return nil, err
}
Log.Infof("Issues: %v", issues)

issue, _, err := j.client.Issue.Get(string(issueID), nil)
if err != nil {
return nil, err
}
return issue, nil
}

Expand All @@ -56,7 +61,7 @@ func (j *Jira) LinkIssueToRepo(owner string, repo RepoConfigName, issueID IssueI
pullRequestURL := fmt.Sprintf("https://github.com/%s/%s/pull/%s", owner, repo, pullRequestID)

comment := jira.Comment{
Body: fmt.Sprintf("A new pull request has been linked: %s", pullRequestURL),
Body: fmt.Sprintf("Working on changes here: %s", pullRequestURL),
}
_, _, err := j.client.Issue.AddComment(string(issueID), &comment)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func OpenPullRequest(issueID IssueID) error {
return err
}

issueBackend, err := getIssueBackendConfigurator(config.GetBackend(profile.RepoBackend))
issueBackend, err := getIssueBackendConfigurator(config.GetBackend(profile.IssueBackend))
if err != nil {
return err
}
Expand Down
43 changes: 36 additions & 7 deletions pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,46 @@ func createBranch(dir, branchName string, gitUser *GitUser) error {
return err
}

Log.V(3).Infof("git checkout -b %v", branchName)
cmd := exec.Command("git", "checkout", "-b", branchName)
cmd.Dir = dir
if err := cmd.Run(); err != nil {
exists, err := branchExists(dir, branchName)
if err != nil {
return err
}

Log.V(3).Infof("git push --set-upstream origin %v", branchName)
cmd = exec.Command("git", "push", "--set-upstream", "origin", branchName)
if exists {
Log.V(3).Infof("git checkout %v", branchName)
cmd := exec.Command("git", "checkout", branchName)
cmd.Dir = dir
if err := cmd.Run(); err != nil {
return err
}
} else {
Log.V(3).Infof("git checkout -b %v", branchName)
cmd := exec.Command("git", "checkout", "-b", branchName)
cmd.Dir = dir
if err := cmd.Run(); err != nil {
return err
}

Log.V(3).Infof("git push --set-upstream origin %v", branchName)
cmd = exec.Command("git", "push", "--set-upstream", "origin", branchName)
cmd.Dir = dir
if err := cmd.Run(); err != nil {
return err
}
}

return nil
}

// branchExists checks if a branch exists in the repository located at dir.
func branchExists(dir, branchName string) (bool, error) {
cmd := exec.Command("git", "branch", "--list", branchName)
cmd.Dir = dir
return cmd.Run()
output, err := cmd.Output()
if err != nil {
return false, err
}
return len(output) > 0, nil
}

// setRepoIdentity sets local git config username, email and ssh command.
Expand Down

0 comments on commit c3b9d6f

Please sign in to comment.