diff options
author | Amine Hilaly <hilalyamine@gmail.com> | 2019-07-19 18:56:58 +0200 |
---|---|---|
committer | Amine Hilaly <hilalyamine@gmail.com> | 2019-07-23 17:18:04 +0200 |
commit | b9a533804940989617890b84d5008e8bb7c8e15b (patch) | |
tree | 71b3dc66c2e7a2f1396dd4e87860c63afff5f4e3 /bridge | |
parent | 7726bbdbcf8aa49548ecbcfc323b47b0ec034f54 (diff) | |
download | git-bug-b9a533804940989617890b84d5008e8bb7c8e15b.tar.gz |
bridge/gitlab: move constants to gitlab.go
Diffstat (limited to 'bridge')
-rw-r--r-- | bridge/gitlab/export.go | 57 | ||||
-rw-r--r-- | bridge/gitlab/gitlab.go | 17 | ||||
-rw-r--r-- | bridge/gitlab/import.go | 6 |
3 files changed, 59 insertions, 21 deletions
diff --git a/bridge/gitlab/export.go b/bridge/gitlab/export.go index 2f70e01a..bf48e31a 100644 --- a/bridge/gitlab/export.go +++ b/bridge/gitlab/export.go @@ -18,12 +18,6 @@ var ( ErrMissingIdentityToken = errors.New("missing identity token") ) -const ( - keyGitlabId = "gitlab-id" - keyGitlabUrl = "gitlab-url" - keyOrigin = "origin" -) - // gitlabExporter implement the Exporter interface type gitlabExporter struct { conf core.Configuration @@ -288,7 +282,7 @@ func (ge *gitlabExporter) exportBug(b *cache.BugCache, since time.Time, out chan if targetHash == bugCreationHash { // case bug creation operation: we need to edit the Gitlab issue - if err := updateGitlabIssueBody(client, bugGitlabID, opr.Message); err != nil { + if err := updateGitlabIssueBody(client, 0, opr.Message); err != nil { err := errors.Wrap(err, "editing issue") out <- core.NewExportError(err, b.Id()) return @@ -323,7 +317,7 @@ func (ge *gitlabExporter) exportBug(b *cache.BugCache, since time.Time, out chan case *bug.SetStatusOperation: opr := op.(*bug.SetStatusOperation) - if err := updateGitlabIssueStatus(client, bugGitlabID, opr.Status); err != nil { + if err := updateGitlabIssueStatus(client, 0, opr.Status); err != nil { err := errors.Wrap(err, "editing status") out <- core.NewExportError(err, b.Id()) return @@ -336,7 +330,7 @@ func (ge *gitlabExporter) exportBug(b *cache.BugCache, since time.Time, out chan case *bug.SetTitleOperation: opr := op.(*bug.SetTitleOperation) - if err := updateGitlabIssueTitle(client, bugGitlabID, opr.Title); err != nil { + if err := updateGitlabIssueTitle(client, 0, opr.Title); err != nil { err := errors.Wrap(err, "editing title") out <- core.NewExportError(err, b.Id()) return @@ -466,8 +460,16 @@ func (ge *gitlabExporter) getLabelsIDs(gc *gitlab.Client, repositoryID string, l // create a gitlab. issue and return it ID func createGitlabIssue(gc *gitlab.Client, repositoryID, title, body string) (string, string, error) { - return "", "", nil + issue, _, err := gc.Issues.CreateIssue(repositoryID, &gitlab.CreateIssueOptions{ + Title: &title, + Description: &body, + }) + if err != nil { + return "", "", err + } + + return strconv.Itoa(issue.IID), issue.WebURL, nil } // add a comment to an issue and return it ID @@ -479,16 +481,39 @@ func editCommentGitlabIssue(gc *gitlab.Client, commentID, body string) (string, return "", "", nil } -func updateGitlabIssueStatus(gc *gitlab.Client, id string, status bug.Status) error { - return nil +func updateGitlabIssueStatus(gc *gitlab.Client, id int, status bug.Status) error { + var state string + + switch status { + case bug.OpenStatus: + state = "reopen" + case bug.ClosedStatus: + state = "close" + default: + panic("unknown bug state") + } + + _, _, err := gc.Issues.UpdateIssue("", id, &gitlab.UpdateIssueOptions{ + StateEvent: &state, + }) + + return err } -func updateGitlabIssueBody(gc *gitlab.Client, id string, body string) error { - return nil +func updateGitlabIssueBody(gc *gitlab.Client, id int, body string) error { + _, _, err := gc.Issues.UpdateIssue("", id, &gitlab.UpdateIssueOptions{ + Description: &body, + }) + + return err } -func updateGitlabIssueTitle(gc *gitlab.Client, id, title string) error { - return nil +func updateGitlabIssueTitle(gc *gitlab.Client, id int, title string) error { + _, _, err := gc.Issues.UpdateIssue("", id, &gitlab.UpdateIssueOptions{ + Title: &title, + }) + + return err } // update gitlab. issue labels diff --git a/bridge/gitlab/gitlab.go b/bridge/gitlab/gitlab.go index 9f5807cd..d0faf1ef 100644 --- a/bridge/gitlab/gitlab.go +++ b/bridge/gitlab/gitlab.go @@ -1,11 +1,28 @@ package gitlab import ( + "time" + "github.com/xanzy/go-gitlab" "github.com/MichaelMure/git-bug/bridge/core" ) +const ( + target = "gitlab" + gitlabV4Url = "https://gitlab.com/api/v4" + + keyProjectID = "project-id" + keyGitlabId = "gitlab-id" + keyGitlabUrl = "gitlab-url" + keyGitlabLogin = "gitlab-login" + keyToken = "token" + keyTarget = "target" + keyOrigin = "origin" + + defaultTimeout = 60 * time.Second +) + func init() { core.Register(&Gitlab{}) } diff --git a/bridge/gitlab/import.go b/bridge/gitlab/import.go index 93ad8570..6227767b 100644 --- a/bridge/gitlab/import.go +++ b/bridge/gitlab/import.go @@ -14,10 +14,6 @@ import ( "github.com/MichaelMure/git-bug/util/text" ) -const ( - keyGitlabLogin = "gitlab-login" -) - type gitlabImporter struct { conf core.Configuration @@ -170,7 +166,7 @@ func (gi *gitlabImporter) ensureNote(repo *cache.RepoCache, b *cache.BugCache, n // since gitlab doesn't provide the issue history // we should check for "changed the description" notes and compare issue texts - + // TODO: Check only one time and ignore next 'description change' within one issue if issue.Description != b.Snapshot().Comments[0].Message { // comment edition |