Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Fixes GitLab HTTP 414 content too large. Fixes #8
Browse files Browse the repository at this point in the history
Occurs when an issue's description or a note's body is too large.
This makes the issue creation on target fail. Fixed by shortening
description or body content in this case.
  • Loading branch information
matm committed Feb 10, 2016
1 parent a76f42a commit 2384909
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/command/gitlab-copy/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,18 @@ func (m *migration) migrateIssue(issueID int) error {
iopts.Labels = append(iopts.Labels, label)
}
// Create target issue if not existing (same name)
ni, _, err := target.Issues.CreateIssue(tarProjectID, iopts)
ni, resp, err := target.Issues.CreateIssue(tarProjectID, iopts)
if err != nil {
return fmt.Errorf("target: error creating issue: %s", err.Error())
if resp.StatusCode == http.StatusRequestURITooLong {
fmt.Printf("target: catched a \"%s\" error, shortening issue's decription length ...\n", http.StatusText(resp.StatusCode))
iopts.Description = iopts.Description[:1024]
ni, _, err = target.Issues.CreateIssue(tarProjectID, iopts)
if err != nil {
return fmt.Errorf("target: error creating empty issue: %s", err.Error())
}
} else {
return fmt.Errorf("target: error creating issue: %s", err.Error())
}
}

// Copy related notes (comments)
Expand All @@ -166,10 +175,20 @@ func (m *migration) migrateIssue(issueID int) error {
}
opts := &gitlab.CreateIssueNoteOptions{}
for _, n := range notes {
opts.Body = fmt.Sprintf("%s @%s wrote on %s :\n\n%s", n.Author.Name, n.Author.Username, n.CreatedAt.Format(time.RFC1123), n.Body)
_, _, err := target.Notes.CreateIssueNote(tarProjectID, ni.ID, opts)
head := fmt.Sprintf("%s @%s wrote on %s :", n.Author.Name, n.Author.Username, n.CreatedAt.Format(time.RFC1123))
opts.Body = fmt.Sprintf("%s\n\n%s", head, n.Body)
_, resp, err := target.Notes.CreateIssueNote(tarProjectID, ni.ID, opts)
if err != nil {
return fmt.Errorf("target: error creating note for issue #%d: %s", ni.IID, err.Error())
if resp.StatusCode == http.StatusRequestURITooLong {
fmt.Printf("target: note's body too long, shortening it ...\n")
opts.Body = fmt.Sprintf("%s\n\n%s", head, n.Body[:1024])
_, _, err := target.Notes.CreateIssueNote(tarProjectID, ni.ID, opts)
if err != nil {
return fmt.Errorf("target: error creating note (with shorter body) for issue #%d: %s", ni.IID, err.Error())
}
} else {
return fmt.Errorf("target: error creating note for issue #%d: %s", ni.IID, err.Error())
}
}
}

Expand Down

0 comments on commit 2384909

Please sign in to comment.