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

Method ensureIssue

bridge/github/import.go:178–233  ·  view source on GitHub ↗
(ctx context.Context, repo *cache.RepoCache, issue *issue, issueEdit *userContentEdit)

Source from the content-addressed store, hash-verified

176}
177
178func (gi *githubImporter) ensureIssue(ctx context.Context, repo *cache.RepoCache, issue *issue, issueEdit *userContentEdit) (*cache.BugCache, error) {
179 author, err := gi.ensurePerson(ctx, repo, issue.Author)
180 if err != nil {
181 return nil, err
182 }
183
184 // resolve bug
185 b, err := repo.Bugs().ResolveMatcher(func(excerpt *cache.BugExcerpt) bool {
186 return excerpt.CreateMetadata[metaKeyGithubUrl] == issue.Url.String() &&
187 excerpt.CreateMetadata[metaKeyGithubId] == parseId(issue.Id)
188 })
189 if err == nil {
190 return b, nil
191 }
192 if !entity.IsErrNotFound(err) {
193 return nil, err
194 }
195
196 // At Github there exist issues with seemingly empty titles. An example is
197 // https://github.com/NixOS/nixpkgs/issues/72730 (here the title is actually
198 // a zero width space U+200B).
199 // Set title to some non-empty string, since git-bug does not accept empty titles.
200 title := text.CleanupOneLine(string(issue.Title))
201 if text.Empty(title) {
202 title = EmptyTitlePlaceholder
203 }
204
205 var textInput string
206 if issueEdit != nil {
207 // use the first issue edit: it represents the bug creation itself
208 textInput = string(*issueEdit.Diff)
209 } else {
210 // if there are no issue edits then the issue struct holds the bug creation
211 textInput = string(issue.Body)
212 }
213
214 // create bug
215 b, _, err = repo.Bugs().NewRaw(
216 author,
217 issue.CreatedAt.Unix(),
218 text.CleanupOneLine(title), // TODO: this is the *current* title, not the original one
219 text.Cleanup(textInput),
220 nil,
221 map[string]string{
222 core.MetaKeyOrigin: target,
223 metaKeyGithubId: parseId(issue.Id),
224 metaKeyGithubUrl: issue.Url.String(),
225 })
226 if err != nil {
227 return nil, err
228 }
229 // importing a new bug
230 gi.out <- core.NewImportBug(b.Id())
231
232 return b, nil
233}
234
235func (gi *githubImporter) ensureIssueEdit(ctx context.Context, repo *cache.RepoCache, bug *cache.BugCache, ghIssueId githubv4.ID, edit *userContentEdit) error {

Callers 1

ImportAllMethod · 0.95

Calls 12

ensurePersonMethod · 0.95
IsErrNotFoundFunction · 0.92
CleanupOneLineFunction · 0.92
EmptyFunction · 0.92
CleanupFunction · 0.92
NewImportBugFunction · 0.92
parseIdFunction · 0.85
ResolveMatcherMethod · 0.80
BugsMethod · 0.80
StringMethod · 0.65
IdMethod · 0.65
NewRawMethod · 0.45

Tested by

no test coverage detected