MCPcopy Index your code
hub / github.com/git-bug/git-bug / exportBug

Method exportBug

bridge/gitlab/export.go:152–407  ·  view source on GitHub ↗

exportBug publish bugs and related events

(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult)

Source from the content-addressed store, hash-verified

150
151// exportBug publish bugs and related events
152func (ge *gitlabExporter) exportBug(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult) {
153 snapshot := b.Snapshot()
154
155 var bugUpdated bool
156 var err error
157 var bugGitlabID int
158 var bugGitlabIDString string
159 var GitlabBaseUrl string
160 var bugCreationId string
161
162 // Special case:
163 // if a user try to export a bug that is not already exported to Gitlab (or imported
164 // from Gitlab) and we do not have the token of the bug author, there is nothing we can do.
165
166 // skip bug if origin is not allowed
167 origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin)
168 if ok && origin != target {
169 out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin))
170 return
171 }
172
173 // first operation is always createOp
174 createOp := snapshot.Operations[0].(*bug.CreateOperation)
175 author := snapshot.Author
176
177 // get gitlab bug ID
178 gitlabID, ok := snapshot.GetCreateMetadata(metaKeyGitlabId)
179 if ok {
180 gitlabBaseUrl, ok := snapshot.GetCreateMetadata(metaKeyGitlabBaseUrl)
181 if ok && gitlabBaseUrl != ge.conf[confKeyGitlabBaseUrl] {
182 out <- core.NewExportNothing(b.Id(), "skipping issue imported from another Gitlab instance")
183 return
184 }
185
186 projectID, ok := snapshot.GetCreateMetadata(metaKeyGitlabProject)
187 if !ok {
188 err := fmt.Errorf("expected to find gitlab project id")
189 out <- core.NewExportError(err, b.Id())
190 return
191 }
192
193 if projectID != ge.conf[confKeyProjectID] {
194 out <- core.NewExportNothing(b.Id(), "skipping issue imported from another repository")
195 return
196 }
197
198 // will be used to mark operation related to a bug as exported
199 bugGitlabIDString = gitlabID
200 bugGitlabID, err = strconv.Atoi(bugGitlabIDString)
201 if err != nil {
202 out <- core.NewExportError(fmt.Errorf("unexpected gitlab id format: %s", bugGitlabIDString), b.Id())
203 return
204 }
205
206 } else {
207 // check that we have a token for operation author
208 client, err := ge.getIdentityClient(author.Id())
209 if err != nil {

Callers 1

ExportAllMethod · 0.95

Calls 15

getIdentityClientMethod · 0.95
NewExportNothingFunction · 0.92
NewExportErrorFunction · 0.92
NewExportBugFunction · 0.92
NewExportCommentFunction · 0.92
NewExportCommentEditionFunction · 0.92
NewExportStatusChangeFunction · 0.92
NewExportTitleEditionFunction · 0.92
NewExportLabelChangeFunction · 0.92
createGitlabIssueFunction · 0.85
addCommentGitlabIssueFunction · 0.85
updateGitlabIssueBodyFunction · 0.85

Tested by

no test coverage detected