2019-07-09 23:58:15 +03:00
|
|
|
package gitlab
|
|
|
|
|
|
|
|
import (
|
2019-07-26 04:22:07 +03:00
|
|
|
"fmt"
|
|
|
|
"strconv"
|
2019-07-09 23:58:15 +03:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
2019-07-26 04:22:07 +03:00
|
|
|
"github.com/xanzy/go-gitlab"
|
2019-07-09 23:58:15 +03:00
|
|
|
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core"
|
2019-07-26 04:22:07 +03:00
|
|
|
"github.com/MichaelMure/git-bug/bug"
|
2019-07-09 23:58:15 +03:00
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2019-08-13 21:51:39 +03:00
|
|
|
"github.com/MichaelMure/git-bug/entity"
|
2019-07-09 23:58:15 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrMissingIdentityToken = errors.New("missing identity token")
|
|
|
|
)
|
|
|
|
|
|
|
|
// gitlabExporter implement the Exporter interface
|
2019-07-26 04:22:07 +03:00
|
|
|
type gitlabExporter struct {
|
|
|
|
conf core.Configuration
|
|
|
|
|
|
|
|
// cache identities clients
|
|
|
|
identityClient map[string]*gitlab.Client
|
|
|
|
|
|
|
|
// map identities with their tokens
|
|
|
|
identityToken map[string]string
|
|
|
|
|
|
|
|
// gitlab repository ID
|
|
|
|
repositoryID string
|
|
|
|
|
|
|
|
// cache identifiers used to speed up exporting operations
|
|
|
|
// cleared for each bug
|
|
|
|
cachedOperationIDs map[string]string
|
|
|
|
|
|
|
|
// cache labels used to speed up exporting labels events
|
|
|
|
cachedLabels map[string]string
|
|
|
|
}
|
2019-07-09 23:58:15 +03:00
|
|
|
|
|
|
|
// Init .
|
|
|
|
func (ge *gitlabExporter) Init(conf core.Configuration) error {
|
2019-07-26 04:22:07 +03:00
|
|
|
ge.conf = conf
|
|
|
|
//TODO: initialize with multiple tokens
|
|
|
|
ge.identityToken = make(map[string]string)
|
|
|
|
ge.identityClient = make(map[string]*gitlab.Client)
|
|
|
|
ge.cachedOperationIDs = make(map[string]string)
|
|
|
|
ge.cachedLabels = make(map[string]string)
|
|
|
|
|
2019-07-09 23:58:15 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-26 04:22:07 +03:00
|
|
|
// getIdentityClient return a gitlab v4 API client configured with the access token of the given identity.
|
|
|
|
// if no client were found it will initialize it from the known tokens map and cache it for next use
|
2019-08-13 21:51:39 +03:00
|
|
|
func (ge *gitlabExporter) getIdentityClient(id entity.Id) (*gitlab.Client, error) {
|
|
|
|
client, ok := ge.identityClient[id.String()]
|
2019-07-26 04:22:07 +03:00
|
|
|
if ok {
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// get token
|
2019-08-13 21:51:39 +03:00
|
|
|
token, ok := ge.identityToken[id.String()]
|
2019-07-26 04:22:07 +03:00
|
|
|
if !ok {
|
|
|
|
return nil, ErrMissingIdentityToken
|
|
|
|
}
|
|
|
|
|
|
|
|
// create client
|
|
|
|
client = buildClient(token)
|
|
|
|
// cache client
|
2019-08-13 21:51:39 +03:00
|
|
|
ge.identityClient[id.String()] = client
|
2019-07-26 04:22:07 +03:00
|
|
|
|
|
|
|
return client, nil
|
|
|
|
}
|
|
|
|
|
2019-07-09 23:58:15 +03:00
|
|
|
// ExportAll export all event made by the current user to Gitlab
|
|
|
|
func (ge *gitlabExporter) ExportAll(repo *cache.RepoCache, since time.Time) (<-chan core.ExportResult, error) {
|
2019-07-26 04:22:07 +03:00
|
|
|
out := make(chan core.ExportResult)
|
|
|
|
|
|
|
|
user, err := repo.GetUserIdentity()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
ge.identityToken[user.Id().String()] = ge.conf[keyToken]
|
2019-07-26 04:22:07 +03:00
|
|
|
|
|
|
|
// get repository node id
|
|
|
|
ge.repositoryID = ge.conf[keyProjectID]
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
defer close(out)
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
var allIdentitiesIds []entity.Id
|
2019-07-26 04:22:07 +03:00
|
|
|
for id := range ge.identityToken {
|
2019-08-13 21:51:39 +03:00
|
|
|
allIdentitiesIds = append(allIdentitiesIds, entity.Id(id))
|
2019-07-26 04:22:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
allBugsIds := repo.AllBugsIds()
|
|
|
|
|
|
|
|
for _, id := range allBugsIds {
|
|
|
|
b, err := repo.ResolveBug(id)
|
|
|
|
if err != nil {
|
|
|
|
out <- core.NewExportError(err, id)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot := b.Snapshot()
|
|
|
|
|
|
|
|
// ignore issues created before since date
|
|
|
|
// TODO: compare the Lamport time instead of using the unix time
|
|
|
|
if snapshot.CreatedAt.Before(since) {
|
|
|
|
out <- core.NewExportNothing(b.Id(), "bug created before the since date")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if snapshot.HasAnyActor(allIdentitiesIds...) {
|
|
|
|
// try to export the bug and it associated events
|
|
|
|
ge.exportBug(b, since, out)
|
|
|
|
} else {
|
|
|
|
out <- core.NewExportNothing(id, "not an actor")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// exportBug publish bugs and related events
|
|
|
|
func (ge *gitlabExporter) exportBug(b *cache.BugCache, since time.Time, out chan<- core.ExportResult) {
|
|
|
|
snapshot := b.Snapshot()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
var bugGitlabID int
|
|
|
|
var bugGitlabIDString string
|
2019-08-13 21:51:39 +03:00
|
|
|
var bugCreationId string
|
|
|
|
|
2019-07-26 04:22:07 +03:00
|
|
|
//labels := make([]string, 0)
|
|
|
|
|
|
|
|
// Special case:
|
|
|
|
// if a user try to export a bug that is not already exported to Gitlab (or imported
|
|
|
|
// from Gitlab) and we do not have the token of the bug author, there is nothing we can do.
|
|
|
|
|
|
|
|
// skip bug if origin is not allowed
|
|
|
|
origin, ok := snapshot.GetCreateMetadata(core.KeyOrigin)
|
|
|
|
if ok && origin != target {
|
|
|
|
out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// first operation is always createOp
|
|
|
|
createOp := snapshot.Operations[0].(*bug.CreateOperation)
|
|
|
|
author := snapshot.Author
|
|
|
|
|
|
|
|
// get gitlab bug ID
|
|
|
|
gitlabID, ok := snapshot.GetCreateMetadata(keyGitlabId)
|
|
|
|
if ok {
|
2019-08-13 21:51:39 +03:00
|
|
|
_, ok := snapshot.GetCreateMetadata(keyGitlabUrl)
|
2019-07-26 04:22:07 +03:00
|
|
|
if !ok {
|
|
|
|
// if we find gitlab ID, gitlab URL must be found too
|
|
|
|
err := fmt.Errorf("expected to find gitlab issue URL")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
2019-08-13 21:51:39 +03:00
|
|
|
return
|
2019-07-26 04:22:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
out <- core.NewExportNothing(b.Id(), "bug already exported")
|
2019-08-13 21:51:39 +03:00
|
|
|
|
2019-07-26 04:22:07 +03:00
|
|
|
// will be used to mark operation related to a bug as exported
|
|
|
|
bugGitlabIDString = gitlabID
|
|
|
|
bugGitlabID, err = strconv.Atoi(bugGitlabIDString)
|
|
|
|
if err != nil {
|
|
|
|
panic("unexpected gitlab id format")
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// check that we have a token for operation author
|
|
|
|
client, err := ge.getIdentityClient(author.Id())
|
|
|
|
if err != nil {
|
|
|
|
// if bug is still not exported and we do not have the author stop the execution
|
|
|
|
out <- core.NewExportNothing(b.Id(), fmt.Sprintf("missing author token"))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// create bug
|
|
|
|
id, url, err := createGitlabIssue(client, ge.repositoryID, createOp.Title, createOp.Message)
|
|
|
|
if err != nil {
|
|
|
|
err := errors.Wrap(err, "exporting gitlab issue")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
idString := strconv.Itoa(id)
|
|
|
|
|
|
|
|
out <- core.NewExportBug(b.Id())
|
|
|
|
|
|
|
|
// mark bug creation operation as exported
|
2019-08-13 21:51:39 +03:00
|
|
|
if err := markOperationAsExported(b, createOp.Id(), idString, url); err != nil {
|
2019-07-26 04:22:07 +03:00
|
|
|
err := errors.Wrap(err, "marking operation as exported")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// commit operation to avoid creating multiple issues with multiple pushes
|
|
|
|
if err := b.CommitAsNeeded(); err != nil {
|
|
|
|
err := errors.Wrap(err, "bug commit")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// cache bug gitlab ID and URL
|
|
|
|
bugGitlabID = id
|
|
|
|
bugGitlabIDString = idString
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
bugCreationId = createOp.Id().String()
|
2019-07-26 04:22:07 +03:00
|
|
|
// cache operation gitlab id
|
2019-08-13 21:51:39 +03:00
|
|
|
ge.cachedOperationIDs[bugCreationId] = bugGitlabIDString
|
2019-07-26 04:22:07 +03:00
|
|
|
|
|
|
|
for _, op := range snapshot.Operations[1:] {
|
|
|
|
// ignore SetMetadata operations
|
|
|
|
if _, ok := op.(*bug.SetMetadataOperation); ok {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore operations already existing in gitlab (due to import or export)
|
|
|
|
// cache the ID of already exported or imported issues and events from Gitlab
|
|
|
|
if id, ok := op.GetMetadata(keyGitlabId); ok {
|
2019-08-13 21:51:39 +03:00
|
|
|
ge.cachedOperationIDs[op.Id().String()] = id
|
|
|
|
out <- core.NewExportNothing(op.Id(), "already exported operation")
|
2019-07-26 04:22:07 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
opAuthor := op.GetAuthor()
|
|
|
|
client, err := ge.getIdentityClient(opAuthor.Id())
|
|
|
|
if err != nil {
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportNothing(op.Id(), "missing operation author token")
|
2019-07-26 04:22:07 +03:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
var id int
|
|
|
|
var idString, url string
|
|
|
|
switch op.(type) {
|
|
|
|
case *bug.AddCommentOperation:
|
|
|
|
opr := op.(*bug.AddCommentOperation)
|
|
|
|
|
|
|
|
// send operation to gitlab
|
|
|
|
id, err = addCommentGitlabIssue(client, ge.repositoryID, bugGitlabID, opr.Message)
|
|
|
|
if err != nil {
|
|
|
|
err := errors.Wrap(err, "adding comment")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportComment(op.Id())
|
2019-07-26 04:22:07 +03:00
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
idString = strconv.Itoa(id)
|
2019-07-26 04:22:07 +03:00
|
|
|
// cache comment id
|
2019-08-13 21:51:39 +03:00
|
|
|
ge.cachedOperationIDs[op.Id().String()] = idString
|
2019-07-26 04:22:07 +03:00
|
|
|
|
|
|
|
case *bug.EditCommentOperation:
|
|
|
|
opr := op.(*bug.EditCommentOperation)
|
2019-08-13 21:51:39 +03:00
|
|
|
targetId := opr.Target.String()
|
2019-07-26 04:22:07 +03:00
|
|
|
|
|
|
|
// Since gitlab doesn't consider the issue body as a comment
|
2019-08-13 21:51:39 +03:00
|
|
|
if targetId == bugCreationId {
|
2019-07-26 04:22:07 +03:00
|
|
|
|
|
|
|
// case bug creation operation: we need to edit the Gitlab issue
|
2019-08-13 21:51:39 +03:00
|
|
|
if err := updateGitlabIssueBody(client, ge.repositoryID, bugGitlabID, opr.Message); err != nil {
|
2019-07-26 04:22:07 +03:00
|
|
|
err := errors.Wrap(err, "editing issue")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportCommentEdition(op.Id())
|
2019-07-26 04:22:07 +03:00
|
|
|
id = bugGitlabID
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// case comment edition operation: we need to edit the Gitlab comment
|
2019-08-13 21:51:39 +03:00
|
|
|
commentID, ok := ge.cachedOperationIDs[targetId]
|
2019-07-26 04:22:07 +03:00
|
|
|
if !ok {
|
|
|
|
panic("unexpected error: comment id not found")
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
commentIDint, err := strconv.Atoi(commentID)
|
2019-07-26 04:22:07 +03:00
|
|
|
if err != nil {
|
2019-08-13 21:51:39 +03:00
|
|
|
panic("unexpected comment id format")
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := editCommentGitlabIssue(client, ge.repositoryID, commentIDint, id, opr.Message); err != nil {
|
2019-07-26 04:22:07 +03:00
|
|
|
err := errors.Wrap(err, "editing comment")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportCommentEdition(op.Id())
|
|
|
|
id = commentIDint
|
2019-07-26 04:22:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
case *bug.SetStatusOperation:
|
|
|
|
opr := op.(*bug.SetStatusOperation)
|
|
|
|
if err := updateGitlabIssueStatus(client, idString, id, opr.Status); err != nil {
|
|
|
|
err := errors.Wrap(err, "editing status")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportStatusChange(op.Id())
|
2019-07-26 04:22:07 +03:00
|
|
|
id = bugGitlabID
|
|
|
|
|
|
|
|
case *bug.SetTitleOperation:
|
|
|
|
opr := op.(*bug.SetTitleOperation)
|
|
|
|
if err := updateGitlabIssueTitle(client, ge.repositoryID, id, opr.Title); err != nil {
|
|
|
|
err := errors.Wrap(err, "editing title")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportTitleEdition(op.Id())
|
2019-07-26 04:22:07 +03:00
|
|
|
id = bugGitlabID
|
|
|
|
|
|
|
|
case *bug.LabelChangeOperation:
|
|
|
|
_ = op.(*bug.LabelChangeOperation)
|
|
|
|
if err := updateGitlabIssueLabels(client, ge.repositoryID, bugGitlabID, []string{}); err != nil {
|
|
|
|
err := errors.Wrap(err, "updating labels")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
out <- core.NewExportLabelChange(op.Id())
|
2019-07-26 04:22:07 +03:00
|
|
|
id = bugGitlabID
|
|
|
|
default:
|
|
|
|
panic("unhandled operation type case")
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark operation as exported
|
2019-08-13 21:51:39 +03:00
|
|
|
if err := markOperationAsExported(b, op.Id(), idString, url); err != nil {
|
2019-07-26 04:22:07 +03:00
|
|
|
err := errors.Wrap(err, "marking operation as exported")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// commit at each operation export to avoid exporting same events multiple times
|
|
|
|
if err := b.CommitAsNeeded(); err != nil {
|
|
|
|
err := errors.Wrap(err, "bug commit")
|
|
|
|
out <- core.NewExportError(err, b.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-13 21:51:39 +03:00
|
|
|
func markOperationAsExported(b *cache.BugCache, target entity.Id, gitlabID, gitlabURL string) error {
|
2019-07-26 04:22:07 +03:00
|
|
|
_, err := b.SetMetadata(
|
|
|
|
target,
|
|
|
|
map[string]string{
|
|
|
|
keyGitlabId: gitlabID,
|
|
|
|
keyGitlabUrl: gitlabURL,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ge *gitlabExporter) getGitlabLabelID(label string) (string, error) {
|
|
|
|
id, ok := ge.cachedLabels[label]
|
|
|
|
if !ok {
|
|
|
|
return "", fmt.Errorf("non cached label")
|
|
|
|
}
|
|
|
|
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// get label from gitlab
|
|
|
|
func (ge *gitlabExporter) loadLabelsFromGitlab(gc *gitlab.Client) error {
|
|
|
|
labels, _, err := gc.Labels.ListLabels(
|
|
|
|
ge.repositoryID,
|
|
|
|
&gitlab.ListLabelsOptions{
|
|
|
|
Page: 0,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, label := range labels {
|
|
|
|
ge.cachedLabels[label.Name] = strconv.Itoa(label.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
for page := 2; len(labels) != 0; page++ {
|
|
|
|
|
|
|
|
labels, _, err = gc.Labels.ListLabels(
|
|
|
|
ge.repositoryID,
|
|
|
|
&gitlab.ListLabelsOptions{
|
|
|
|
Page: page,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, label := range labels {
|
|
|
|
ge.cachedLabels[label.Name] = strconv.Itoa(label.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ge *gitlabExporter) createGitlabLabel(gc *gitlab.Client, label bug.Label) error {
|
|
|
|
client := buildClient(ge.conf[keyToken])
|
|
|
|
|
|
|
|
// RGBA to hex color
|
|
|
|
rgba := label.RGBA()
|
|
|
|
hexColor := fmt.Sprintf("%.2x%.2x%.2x", rgba.R, rgba.G, rgba.B)
|
|
|
|
name := label.String()
|
|
|
|
|
|
|
|
_, _, err := client.Labels.CreateLabel(ge.repositoryID, &gitlab.CreateLabelOptions{
|
|
|
|
Name: &name,
|
|
|
|
Color: &hexColor,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// create a gitlab. issue and return it ID
|
|
|
|
func createGitlabIssue(gc *gitlab.Client, repositoryID, title, body string) (int, string, error) {
|
|
|
|
issue, _, err := gc.Issues.CreateIssue(repositoryID, &gitlab.CreateIssueOptions{
|
|
|
|
Title: &title,
|
|
|
|
Description: &body,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return 0, "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return issue.IID, issue.WebURL, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// add a comment to an issue and return it ID
|
|
|
|
func addCommentGitlabIssue(gc *gitlab.Client, repositoryID string, issueID int, body string) (int, error) {
|
|
|
|
note, _, err := gc.Notes.CreateIssueNote(repositoryID, issueID, &gitlab.CreateIssueNoteOptions{
|
|
|
|
Body: &body,
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return note.ID, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func editCommentGitlabIssue(gc *gitlab.Client, repositoryID string, issueID, noteID int, body string) error {
|
|
|
|
_, _, err := gc.Notes.UpdateIssueNote(repositoryID, issueID, noteID, &gitlab.UpdateIssueNoteOptions{
|
|
|
|
Body: &body,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateGitlabIssueStatus(gc *gitlab.Client, repositoryID string, issueID 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(repositoryID, issueID, &gitlab.UpdateIssueOptions{
|
|
|
|
StateEvent: &state,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateGitlabIssueBody(gc *gitlab.Client, repositoryID string, issueID int, body string) error {
|
|
|
|
_, _, err := gc.Issues.UpdateIssue(repositoryID, issueID, &gitlab.UpdateIssueOptions{
|
|
|
|
Description: &body,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateGitlabIssueTitle(gc *gitlab.Client, repositoryID string, issueID int, title string) error {
|
|
|
|
_, _, err := gc.Issues.UpdateIssue(repositoryID, issueID, &gitlab.UpdateIssueOptions{
|
|
|
|
Title: &title,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// update gitlab. issue labels
|
|
|
|
func updateGitlabIssueLabels(gc *gitlab.Client, repositoryID string, issueID int, labels []string) error {
|
|
|
|
_, _, err := gc.Issues.UpdateIssue(repositoryID, issueID, &gitlab.UpdateIssueOptions{
|
|
|
|
Labels: labels,
|
|
|
|
})
|
|
|
|
|
|
|
|
return err
|
2019-07-09 23:58:15 +03:00
|
|
|
}
|