Documentation
¶
Index ¶
- Variables
- func AutofillMRFromCommits(targetBranch, sourceBranch string, fillCommitBody bool) (string, string, error)
- func DiffPosition(ctx context.Context, client *gitlab.Client, project string, mrIID int64, ...) (*gitlab.PositionOptions, error)
- func DisplayAllMRs(streams *iostreams.IOStreams, mrs []*gitlab.BasicMergeRequest) string
- func DisplayMR(c *iostreams.ColorPalette, mr *gitlab.BasicMergeRequest, isTTY bool) string
- func FilterDiscussions(discussions []*gitlab.Discussion, opts FilterOpts) []*gitlab.Discussion
- func FindNoteInDiscussionPaginated(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, ...) (string, *gitlab.Note, error)
- func GenerateMRCommitListBody(commits []*git.Commit, fillCommitBody bool) (string, error)
- func GenerateMRTitleAndBody(commits []*git.Commit, sourceBranch string, fillCommitBody bool) (string, string, error)
- func GetDraftNote(ctx context.Context, client *gitlab.Client, projectID any, ...) (*gitlab.DraftNote, error)
- func HasFilePosition(pos *gitlab.NotePosition) bool
- func IsInternalDiscussion(discussion *gitlab.Discussion) bool
- func ListAllDraftNotes(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64) ([]*gitlab.DraftNote, error)
- func MRCheckErrors(mr *gitlab.MergeRequest, err MRCheckErrOptions) error
- func MRFromArgs(ctx context.Context, f cmdutils.Factory, args []string, state string) (*gitlab.MergeRequest, glrepo.Interface, error)
- func MRFromArgsWithOpts(ctx context.Context, f cmdutils.Factory, args []string, ...) (*gitlab.MergeRequest, glrepo.Interface, error)
- func MRState(c *iostreams.ColorPalette, m *gitlab.BasicMergeRequest) string
- func MRWebURLFromArgs(ctx context.Context, f cmdutils.Factory, args []string, state string) (string, glrepo.Interface, error)
- func MRsFromArgs(ctx context.Context, f cmdutils.Factory, args []string, state string) ([]*gitlab.MergeRequest, glrepo.Interface, error)
- func NoteBodyFromStdinOrEditor(ctx context.Context, ios *iostreams.IOStreams, cfg func() config.Config) (string, error)
- func NotePreview(body string) string
- func PrintCommentFileContext(out io.Writer, c *iostreams.ColorPalette, pos *gitlab.NotePosition)
- func PrintDiscussions(out io.Writer, ios *iostreams.IOStreams, discussions []*gitlab.Discussion, ...)
- func PrintDraftNotes(ios *iostreams.IOStreams, drafts []*gitlab.DraftNote)
- func PrintMRApprovalState(ios *iostreams.IOStreams, mrApprovals *gitlab.MergeRequestApprovalState)
- func RebaseMR(ios *iostreams.IOStreams, apiClient *gitlab.Client, repo glrepo.Interface, ...) error
- func ResolveDiscussion(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, ...) (*gitlab.Discussion, error)
- func ResolveDiscussionID(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, ...) (string, error)
- func TruncateDiscussionID(id string) string
- type FilterOpts
- type LineRange
- type MRCheckErrOptions
- type MrOptions
- type PrintDiscussionsOptions
Constants ¶
This section is empty.
Variables ¶
var ErrNoteNotFound = errors.New("note not found")
ErrNoteNotFound is returned by FindNoteInDiscussionPaginated when no note with the requested ID exists. Callers can distinguish this from a real lookup failure (a network or API error while paginating) with errors.Is, and should not report the latter as "not found".
var GetMRForBranch = func(ctx context.Context, ios *iostreams.IOStreams, apiClient *gitlab.Client, mrOpts MrOptions) (*gitlab.BasicMergeRequest, error) { owner, currentBranch := resolveOwnerAndBranch(mrOpts.Branch) opts := gitlab.ListProjectMergeRequestsOptions{ SourceBranch: new(currentBranch), } userAskedForSpecificState := mrOpts.State != "" && mrOpts.State != "any" if userAskedForSpecificState { opts.State = new(mrOpts.State) } mrs, err := api.ListMRs(apiClient, mrOpts.BaseRepo.FullName(), &opts) if err != nil { return nil, fmt.Errorf("failed to get open merge request for %q: %w", currentBranch, err) } if len(mrs) == 0 { return nil, fmt.Errorf("no open merge request available for %q", currentBranch) } userAskedForSpecificOwner := owner != "" if userAskedForSpecificOwner { for i := range mrs { mr := mrs[i] matchFound := mr.Author.Username == owner if matchFound { return mr, nil } } return nil, fmt.Errorf("no open merge request available for %q owned by @%s", currentBranch, owner) } if len(mrs) == 1 { return mrs[0], nil } mrMap := map[string]*gitlab.BasicMergeRequest{} var mrNames []string for i := range mrs { t := fmt.Sprintf("!%d (%s) by @%s", mrs[i].IID, currentBranch, mrs[i].Author.Username) mrMap[t] = mrs[i] mrNames = append(mrNames, t) } pickedMR := mrNames[0] if !mrOpts.PromptEnabled { err = fmt.Errorf("merge request ID number required. Possible matches:\n\n%s", strings.Join(mrNames, "\n")) } else { err = ios.Select(ctx, &pickedMR, multipleMRSelectQuestion, mrNames) } if err != nil { return nil, fmt.Errorf("you must select a merge request: %w", err) } return mrMap[pickedMR], nil }
var ListAllDiscussions = func(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, opts *gitlab.ListMergeRequestDiscussionsOptions) ([]*gitlab.Discussion, error) { if opts == nil { opts = &gitlab.ListMergeRequestDiscussionsOptions{} } if opts.PerPage == 0 { opts.PerPage = api.DefaultListLimit } var allDiscussions []*gitlab.Discussion page := opts.Page if page == 0 { page = 1 } for { opts.Page = page discussions, resp, err := client.Discussions.ListMergeRequestDiscussions(projectID, mrIID, opts, gitlab.WithContext(ctx)) if err != nil { return nil, err } allDiscussions = append(allDiscussions, discussions...) if resp == nil || resp.NextPage == 0 { break } page = resp.NextPage } return allDiscussions, nil }
ListAllDiscussions fetches all discussions for a merge request, paginating automatically.
Functions ¶
func AutofillMRFromCommits ¶ added in v1.66.0
func AutofillMRFromCommits(targetBranch, sourceBranch string, fillCommitBody bool) (string, string, error)
AutofillMRFromCommits generates title and body from commit information between two branches
func DiffPosition ¶ added in v1.122.0
func DiffPosition(ctx context.Context, client *gitlab.Client, project string, mrIID int64, filePath string, lines LineRange, oldLine int) (*gitlab.PositionOptions, error)
DiffPosition resolves a file path and a --line or --old-line value into a diff position on the latest merge request diff version. Leave lines and oldLine zero for a file-level comment.
func DisplayAllMRs ¶
func DisplayAllMRs(streams *iostreams.IOStreams, mrs []*gitlab.BasicMergeRequest) string
func DisplayMR ¶
func DisplayMR(c *iostreams.ColorPalette, mr *gitlab.BasicMergeRequest, isTTY bool) string
func FilterDiscussions ¶ added in v1.90.0
func FilterDiscussions(discussions []*gitlab.Discussion, opts FilterOpts) []*gitlab.Discussion
FilterDiscussions filters discussions based on the provided options.
func FindNoteInDiscussionPaginated ¶ added in v1.121.0
func FindNoteInDiscussionPaginated(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, noteID int64) (string, *gitlab.Note, error)
FindNoteInDiscussionPaginated finds the discussion and note object for a specific note ID, scanning discussions page by page and returning as soon as a match is found instead of fetching every page first.
Returns ErrNoteNotFound (wrapped, check with errors.Is) if every page is scanned without a match. Any other error indicates a real failure while listing discussions and must not be treated as "not found" by callers.
func GenerateMRCommitListBody ¶ added in v1.66.0
GenerateMRCommitListBody creates a markdown list of commits with optional commit bodies
func GenerateMRTitleAndBody ¶ added in v1.66.0
func GenerateMRTitleAndBody(commits []*git.Commit, sourceBranch string, fillCommitBody bool) (string, string, error)
GenerateMRTitleAndBody creates title and body from commits
func GetDraftNote ¶ added in v1.122.0
func GetDraftNote(ctx context.Context, client *gitlab.Client, projectID any, mrIID, draftNoteID int64) (*gitlab.DraftNote, error)
GetDraftNote returns one of the current user's pending review comments on the merge request.
func HasFilePosition ¶ added in v1.122.0
func HasFilePosition(pos *gitlab.NotePosition) bool
HasFilePosition reports whether pos targets a file. The API returns general pending comments with an empty position object rather than none.
func IsInternalDiscussion ¶ added in v1.120.0
func IsInternalDiscussion(discussion *gitlab.Discussion) bool
IsInternalDiscussion reports whether a thread is internal. GitLab tracks internal per thread rather than per note, so the opening note decides it.
func ListAllDraftNotes ¶ added in v1.122.0
func ListAllDraftNotes(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64) ([]*gitlab.DraftNote, error)
ListAllDraftNotes returns every pending review comment the current user has on the merge request.
func MRCheckErrors ¶
func MRCheckErrors(mr *gitlab.MergeRequest, err MRCheckErrOptions) error
MRCheckErrors checks and return merge request errors specified in MRCheckErrOptions{}
func MRFromArgs ¶
func MRFromArgs(ctx context.Context, f cmdutils.Factory, args []string, state string) (*gitlab.MergeRequest, glrepo.Interface, error)
MRFromArgs is wrapper around MRFromArgsWithOpts without any custom options
func MRFromArgsWithOpts ¶
func MRFromArgsWithOpts( ctx context.Context, f cmdutils.Factory, args []string, opts *gitlab.GetMergeRequestsOptions, state string, ) (*gitlab.MergeRequest, glrepo.Interface, error)
MRFromArgsWithOpts gets MR with custom request options passed down to it
func MRState ¶
func MRState(c *iostreams.ColorPalette, m *gitlab.BasicMergeRequest) string
func MRWebURLFromArgs ¶ added in v1.111.0
func MRWebURLFromArgs(ctx context.Context, f cmdutils.Factory, args []string, state string) (string, glrepo.Interface, error)
MRWebURLFromArgs resolves the web URL of a merge request using as few API calls as possible. When the merge request is identified by branch, the URL is taken from the list response instead of fetching the merge request again.
func MRsFromArgs ¶
func NoteBodyFromStdinOrEditor ¶ added in v1.122.0
func NoteBodyFromStdinOrEditor(ctx context.Context, ios *iostreams.IOStreams, cfg func() config.Config) (string, error)
NoteBodyFromStdinOrEditor reads a note body from standard input when it is not a terminal, and from the configured editor otherwise.
func NotePreview ¶ added in v1.122.0
NotePreview returns body on a single line, cut to 80 runes, for showing in a confirmation prompt.
func PrintCommentFileContext ¶ added in v1.90.0
func PrintCommentFileContext(out io.Writer, c *iostreams.ColorPalette, pos *gitlab.NotePosition)
PrintCommentFileContext prints file and line context for a note position.
func PrintDiscussions ¶ added in v1.108.0
func PrintDiscussions(out io.Writer, ios *iostreams.IOStreams, discussions []*gitlab.Discussion, opts PrintDiscussionsOptions)
PrintDiscussions renders discussions to out.
func PrintDraftNotes ¶ added in v1.122.0
PrintDraftNotes renders pending review comments to standard output.
func PrintMRApprovalState ¶
func PrintMRApprovalState(ios *iostreams.IOStreams, mrApprovals *gitlab.MergeRequestApprovalState)
PrintMRApprovalState renders an output to summarize the approval state of a merge request
func ResolveDiscussion ¶ added in v1.120.0
func ResolveDiscussion(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, prefix string) (*gitlab.Discussion, error)
ResolveDiscussion resolves a prefix (8+ chars) to the discussion it names, for callers that need the thread's notes and not only its ID. Returns an error if the prefix is ambiguous or not found.
func ResolveDiscussionID ¶ added in v1.90.0
func ResolveDiscussionID(ctx context.Context, client *gitlab.Client, projectID any, mrIID int64, prefix string) (string, error)
ResolveDiscussionID resolves a prefix (8+ chars) to a full discussion ID. Returns an error if the prefix is ambiguous or not found.
func TruncateDiscussionID ¶ added in v1.90.0
TruncateDiscussionID truncates a discussion ID to 8 characters with an ellipsis. If the ID is 8 characters or shorter, it is returned unchanged.
Types ¶
type FilterOpts ¶ added in v1.90.0
type FilterOpts struct {
// State filters by resolution status: "resolved", "unresolved", "resolvable", or "" for all.
State string
// Type filters by discussion type: "general", "diff", "system", or "" for all.
Type string
// FilePath filters to discussions on a specific file path.
FilePath string
}
FilterOpts specifies how to filter discussions.
type LineRange ¶ added in v1.122.0
type LineRange struct {
Start, End int
}
LineRange is the value of a --line flag: a single new-side line like "42" or a range like "10:15". It parses during flag parsing, so a malformed value fails before a command prompts for a comment body. The zero value means no line.
type MRCheckErrOptions ¶
type MRCheckErrOptions struct {
// Draft: check and return err if merge request is a DRAFT
Draft bool
// Closed: check and return err if merge request is closed
Closed bool
// Merged: check and return err if merge request is already merged
Merged bool
// Opened: check and return err if merge request is already opened
Opened bool
// Conflict: check and return err if there are merge conflicts
Conflict bool
// PipelineStatus: check and return err pipeline did not succeed and it is required before merging
PipelineStatus bool
// MergePermitted: check and return err if user is not authorized to merge
MergePermitted bool
// Subscribed: check and return err if user is already subscribed to MR
Subscribed bool
// Unsubscribed: check and return err if user is already unsubscribed to MR
Unsubscribed bool
// MergePrivilege: check and return err if user is not authorized to merge
MergePrivilege bool
}