-
-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close issue on merge #871
Open
prarit
wants to merge
2
commits into
zaquestion:master
Choose a base branch
from
prarit:close_issue_on_merge
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Close issue on merge #871
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -19,76 +19,6 @@ import ( | |||||
lab "github.com/zaquestion/lab/internal/gitlab" | ||||||
) | ||||||
|
||||||
// mrCmd represents the mr command | ||||||
var mrCreateCmd = &cobra.Command{ | ||||||
Use: "create [target_remote [target_branch]]", | ||||||
Aliases: []string{"new"}, | ||||||
Short: "Creates a merge request.", | ||||||
Args: cobra.MaximumNArgs(2), | ||||||
Example: heredoc.Doc(` | ||||||
lab mr create target_remote | ||||||
lab mr create target_remote target_branch --allow-collaboration | ||||||
lab mr create upstream main --source my_fork:feature-3 | ||||||
lab mr create a_remote -a johndoe -a janedoe | ||||||
lab mr create my_remote -c | ||||||
lab mr create my_remote --draft | ||||||
lab mr create my_remote -F a_file.txt | ||||||
lab mr create my_remote -F a_file.txt --force-linebreak | ||||||
lab mr create my_remote -f a_file.txt | ||||||
lab mr create my_remote -l bug -l confirmed | ||||||
lab mr create my_remote -m "A title message" | ||||||
lab mr create my_remote -m "A MR title" -m "A MR description" | ||||||
lab mr create my_remote --milestone "Fall" | ||||||
lab mr create my_remote -d | ||||||
lab mr create my_remote -r johndoe -r janedoe | ||||||
lab mr create my_remote -s`), | ||||||
PersistentPreRun: labPersistentPreRun, | ||||||
Run: runMRCreate, | ||||||
} | ||||||
|
||||||
func init() { | ||||||
mrCreateCmd.Flags().StringArrayP("message", "m", []string{}, "use the given <msg>; multiple -m are concatenated as separate paragraphs") | ||||||
mrCreateCmd.Flags().StringSliceP("assignee", "a", []string{}, "set assignee by username; can be specified multiple times for multiple assignees") | ||||||
mrCreateCmd.Flags().StringSliceP("reviewer", "r", []string{}, "set reviewer by username; can be specified multiple times for multiple reviewers") | ||||||
mrCreateCmd.Flags().StringSliceP("label", "l", []string{}, "add label <label>; can be specified multiple times for multiple labels") | ||||||
mrCreateCmd.Flags().BoolP("remove-source-branch", "d", false, "remove source branch from remote after merge") | ||||||
mrCreateCmd.Flags().BoolP("squash", "s", false, "squash commits when merging") | ||||||
mrCreateCmd.Flags().Bool("allow-collaboration", false, "allow commits from other members") | ||||||
mrCreateCmd.Flags().String("milestone", "", "set milestone by milestone title or ID") | ||||||
mrCreateCmd.Flags().StringP("file", "F", "", "use the given file as the Title and Description") | ||||||
mrCreateCmd.Flags().StringP("file-edit", "f", "", "use the given file as the Title and Description and open the editor") | ||||||
mrCreateCmd.Flags().Bool("no-edit", false, "use the selected commit message without opening the editor") | ||||||
mrCreateCmd.Flags().Bool("force-linebreak", false, "append 2 spaces to the end of each line to force markdown linebreaks") | ||||||
mrCreateCmd.Flags().BoolP("cover-letter", "c", false, "comment changelog and diffstat") | ||||||
mrCreateCmd.Flags().Bool("draft", false, "mark the merge request as draft") | ||||||
mrCreateCmd.Flags().String("source", "", "specify the source remote and branch in the form of remote:branch") | ||||||
mergeRequestCmd.Flags().AddFlagSet(mrCreateCmd.Flags()) | ||||||
|
||||||
mrCmd.AddCommand(mrCreateCmd) | ||||||
|
||||||
carapace.Gen(mrCreateCmd).FlagCompletion(carapace.ActionMap{ | ||||||
"label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { | ||||||
project, _, err := parseArgsRemoteAndProject(c.Args) | ||||||
if err != nil { | ||||||
return carapace.ActionMessage(err.Error()) | ||||||
} | ||||||
return action.Labels(project).Invoke(c).Filter(c.Parts).ToA() | ||||||
}), | ||||||
"milestone": carapace.ActionCallback(func(c carapace.Context) carapace.Action { | ||||||
project, _, err := parseArgsRemoteAndProject(c.Args) | ||||||
if err != nil { | ||||||
return carapace.ActionMessage(err.Error()) | ||||||
} | ||||||
return action.Milestones(project, action.MilestoneOpts{Active: true}) | ||||||
}), | ||||||
}) | ||||||
|
||||||
carapace.Gen(mrCreateCmd).PositionalCompletion( | ||||||
action.Remotes(), | ||||||
action.RemoteBranches(0), | ||||||
) | ||||||
} | ||||||
|
||||||
func verifyRemoteBranch(projID string, branch string) error { | ||||||
if _, err := lab.GetCommit(projID, branch); err != nil { | ||||||
return fmt.Errorf("%s is not a valid reference", branch) | ||||||
|
@@ -312,6 +242,23 @@ func runMRCreate(cmd *cobra.Command, args []string) { | |||||
log.Fatal("empty MR message") | ||||||
} | ||||||
|
||||||
closeIssues, err := cmd.Flags().GetStringSlice("close-issue") | ||||||
if err != nil { | ||||||
log.Fatal(err) | ||||||
} | ||||||
|
||||||
if len(closeIssues) > 0 { | ||||||
closeIssueString := "\n\nCloses " | ||||||
for i, issue := range closeIssues { | ||||||
closeIssueString = closeIssueString + "#" + issue | ||||||
if i != (len(closeIssues) - 1) { | ||||||
closeIssueString = closeIssueString + ", " | ||||||
} | ||||||
} | ||||||
closeIssueString += "\n" | ||||||
body += closeIssueString | ||||||
} | ||||||
|
||||||
linebreak, _ := cmd.Flags().GetBool("force-linebreak") | ||||||
if linebreak { | ||||||
body = textToMarkdown(body) | ||||||
|
@@ -444,3 +391,75 @@ func mrText(sourceRemote, sourceBranch, targetRemote, targetBranch string, cover | |||||
|
||||||
return b.String(), nil | ||||||
} | ||||||
|
||||||
// mrCmd represents the mr command | ||||||
var mrCreateCmd = &cobra.Command{ | ||||||
Use: "create [target_remote [target_branch]]", | ||||||
Aliases: []string{"new"}, | ||||||
Short: "Creates a merge request.", | ||||||
Args: cobra.MaximumNArgs(2), | ||||||
Example: heredoc.Doc(` | ||||||
lab mr create target_remote | ||||||
lab mr create target_remote target_branch --allow-collaboration | ||||||
lab mr create upstream main --source my_fork:feature-3 | ||||||
lab mr create a_remote -a johndoe -a janedoe | ||||||
lab mr create my_remote -c | ||||||
lab mr create my_remote --draft | ||||||
lab mr create my_remote -F a_file.txt | ||||||
lab mr create my_remote -F a_file.txt --force-linebreak | ||||||
lab mr create my_remote -f a_file.txt | ||||||
lab mr create my_remote -l bug -l confirmed | ||||||
lab mr create my_remote -m "A title message" | ||||||
lab mr create my_remote -m "A MR title" -m "A MR description" | ||||||
lab mr create my_remote --milestone "Fall" | ||||||
lab mr create my_remote -d | ||||||
lab mr create my_remote -r johndoe -r janedoe | ||||||
lab mr create my_remote -s`), | ||||||
PersistentPreRun: labPersistentPreRun, | ||||||
Run: runMRCreate, | ||||||
} | ||||||
|
||||||
func init() { | ||||||
mrCreateCmd.Flags().StringArrayP("message", "m", []string{}, "use the given <msg>; multiple -m are concatenated as separate paragraphs") | ||||||
mrCreateCmd.Flags().StringSliceP("assignee", "a", []string{}, "set assignee by username; can be specified multiple times for multiple assignees") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. non-blocking-suggestion: This is true for premium/ultimate, as multiple assignees are not allowed on free plan, so I think we should note that on this description, something like:
Suggested change
|
||||||
mrCreateCmd.Flags().StringSliceP("reviewer", "r", []string{}, "set reviewer by username; can be specified multiple times for multiple reviewers") | ||||||
mrCreateCmd.Flags().StringSliceP("label", "l", []string{}, "add label <label>; can be specified multiple times for multiple labels") | ||||||
mrCreateCmd.Flags().BoolP("remove-source-branch", "d", false, "remove source branch from remote after merge") | ||||||
mrCreateCmd.Flags().BoolP("squash", "s", false, "squash commits when merging") | ||||||
mrCreateCmd.Flags().Bool("allow-collaboration", false, "allow commits from other members") | ||||||
mrCreateCmd.Flags().String("milestone", "", "set milestone by milestone title or ID") | ||||||
mrCreateCmd.Flags().StringP("file", "F", "", "use the given file as the Title and Description") | ||||||
mrCreateCmd.Flags().StringP("file-edit", "f", "", "use the given file as the Title and Description and open the editor") | ||||||
mrCreateCmd.Flags().Bool("no-edit", false, "use the selected commit message without opening the editor") | ||||||
mrCreateCmd.Flags().Bool("force-linebreak", false, "append 2 spaces to the end of each line to force markdown linebreaks") | ||||||
mrCreateCmd.Flags().BoolP("cover-letter", "c", false, "comment changelog and diffstat") | ||||||
mrCreateCmd.Flags().Bool("draft", false, "mark the merge request as draft") | ||||||
mrCreateCmd.Flags().String("source", "", "specify the source remote and branch in the form of remote:branch") | ||||||
mrCreateCmd.Flags().StringSlice("close-issue", []string{}, "close issue when this merge request is merged; can be specified multiple times") | ||||||
|
||||||
mergeRequestCmd.Flags().AddFlagSet(mrCreateCmd.Flags()) | ||||||
|
||||||
mrCmd.AddCommand(mrCreateCmd) | ||||||
|
||||||
carapace.Gen(mrCreateCmd).FlagCompletion(carapace.ActionMap{ | ||||||
"label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { | ||||||
project, _, err := parseArgsRemoteAndProject(c.Args) | ||||||
if err != nil { | ||||||
return carapace.ActionMessage(err.Error()) | ||||||
} | ||||||
return action.Labels(project).Invoke(c).Filter(c.Parts).ToA() | ||||||
}), | ||||||
"milestone": carapace.ActionCallback(func(c carapace.Context) carapace.Action { | ||||||
project, _, err := parseArgsRemoteAndProject(c.Args) | ||||||
if err != nil { | ||||||
return carapace.ActionMessage(err.Error()) | ||||||
} | ||||||
return action.Milestones(project, action.MilestoneOpts{Active: true}) | ||||||
}), | ||||||
}) | ||||||
|
||||||
carapace.Gen(mrCreateCmd).PositionalCompletion( | ||||||
action.Remotes(), | ||||||
action.RemoteBranches(0), | ||||||
) | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if
Closes
is in the first line? Does it still work?This is the Gitlab regex just for reference
/^\/(?<cmd>close|reopen|...)(?:( |$))(?<arg>[^\/\n]*)(?:\n|$)/
which if you take all the fuzz, it matches that it is at the start of the line without any break line check.