diff --git a/README.md b/README.md index f256e93..3c3cf94 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/cmd/issuectl/config.go b/cmd/issuectl/config.go index d8174da..85103b0 100644 --- a/cmd/issuectl/config.go +++ b/cmd/issuectl/config.go @@ -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 }, diff --git a/cmd/issuectl/start.go b/cmd/issuectl/start.go index 4fc6430..88395aa 100644 --- a/cmd/issuectl/start.go +++ b/cmd/issuectl/start.go @@ -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 { diff --git a/pkg/backend_jira.go b/pkg/backend_jira.go index e50c299..fc51150 100644 --- a/pkg/backend_jira.go +++ b/pkg/backend_jira.go @@ -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 } @@ -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 { diff --git a/pkg/issue.go b/pkg/issue.go index 19130db..cd2b021 100644 --- a/pkg/issue.go +++ b/pkg/issue.go @@ -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 } diff --git a/pkg/util.go b/pkg/util.go index b926b5e..3fa684f 100644 --- a/pkg/util.go +++ b/pkg/util.go @@ -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.