exportBug publish bugs and related events
(ctx context.Context, b *cache.BugCache, out chan<- core.ExportResult)
| 150 | |
| 151 | // exportBug publish bugs and related events |
| 152 | func (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 { |
no test coverage detected