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

Method exportBug

bridge/github/export.go:199–423  ·  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

197
198// exportBug publish bugs and related events
199func (ge *githubExporter) exportBug(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult) {
200 snapshot := b.Snapshot()
201 var bugUpdated bool
202
203 var bugGithubID string
204 var bugGithubURL string
205
206 // Special case:
207 // if a user try to export a bug that is not already exported to Github (or imported
208 // from Github) and we do not have the token of the bug author, there is nothing we can do.
209
210 // first operation is always createOp
211 createOp := snapshot.Operations[0].(*bug.CreateOperation)
212 author := snapshot.Author
213
214 // skip bug if origin is not allowed
215 origin, ok := snapshot.GetCreateMetadata(core.MetaKeyOrigin)
216 if ok && origin != target {
217 out <- core.NewExportNothing(b.Id(), fmt.Sprintf("issue tagged with origin: %s", origin))
218 return
219 }
220
221 // get github bug ID
222 githubID, ok := snapshot.GetCreateMetadata(metaKeyGithubId)
223 if ok {
224 githubURL, ok := snapshot.GetCreateMetadata(metaKeyGithubUrl)
225 if !ok {
226 // if we find github ID, github URL must be found too
227 err := fmt.Errorf("incomplete Github metadata: expected to find issue URL")
228 out <- core.NewExportError(err, b.Id())
229 }
230
231 // extract owner and project
232 owner, project, err := splitURL(githubURL)
233 if err != nil {
234 err := fmt.Errorf("bad project url: %v", err)
235 out <- core.NewExportError(err, b.Id())
236 return
237 }
238
239 // ignore issue coming from other repositories
240 if owner != ge.conf[confKeyOwner] && project != ge.conf[confKeyProject] {
241 out <- core.NewExportNothing(b.Id(), fmt.Sprintf("skipping issue from url:%s", githubURL))
242 return
243 }
244
245 // will be used to mark operation related to a bug as exported
246 bugGithubID = githubID
247 bugGithubURL = githubURL
248
249 } else {
250 // check that we have a token for operation author
251 client, err := ge.getClientForIdentity(author.Id())
252 if err != nil {
253 // if bug is still not exported and we do not have the author stop the execution
254 out <- core.NewExportNothing(b.Id(), fmt.Sprintf("missing author token"))
255 return
256 }

Callers 1

ExportAllMethod · 0.95

Calls 15

getClientForIdentityMethod · 0.95
createGithubIssueMethod · 0.95
addCommentGithubIssueMethod · 0.95
updateGithubIssueBodyMethod · 0.95
NewExportNothingFunction · 0.92
NewExportErrorFunction · 0.92
NewExportBugFunction · 0.92
NewExportCommentFunction · 0.92

Tested by

no test coverage detected