-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mr/issue: Add subscribe/unsubscribe subcommands
For projects where one is only tangentially involved, it sometimes makes sense to subscribe to an individual issue or merge request rather than the project as a whole. Support that with corresponding subcommands.
- Loading branch information
Showing
5 changed files
with
224 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
"github.com/zaquestion/lab/internal/action" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
var issueSubscribeCmd = &cobra.Command{ | ||
Use: "subscribe [remote] <id>", | ||
Aliases: []string{}, | ||
Short: "Subscribe to issue", | ||
Long: ``, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, id, err := parseArgsRemoteAndID(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p, err := lab.FindProject(rn) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.IssueSubscribe(p.ID, int(id)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Subscribed to issue #%d\n", id) | ||
}, | ||
} | ||
|
||
func init() { | ||
issueCmd.AddCommand(issueSubscribeCmd) | ||
carapace.Gen(issueSubscribeCmd).PositionalCompletion( | ||
action.Remotes(), | ||
action.Issues(issueList), | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
"github.com/zaquestion/lab/internal/action" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
var issueUnsubscribeCmd = &cobra.Command{ | ||
Use: "unsubscribe [remote] <id>", | ||
Aliases: []string{}, | ||
Short: "Unubscribe from issue", | ||
Long: ``, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, id, err := parseArgsRemoteAndID(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p, err := lab.FindProject(rn) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.IssueUnsubscribe(p.ID, int(id)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Unsubscribed from issue #%d\n", id) | ||
}, | ||
} | ||
|
||
func init() { | ||
issueCmd.AddCommand(issueUnsubscribeCmd) | ||
carapace.Gen(issueUnsubscribeCmd).PositionalCompletion( | ||
action.Remotes(), | ||
action.Issues(issueList), | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
"github.com/zaquestion/lab/internal/action" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
var mrSubscribeCmd = &cobra.Command{ | ||
Use: "subscribe [remote] <id>", | ||
Aliases: []string{}, | ||
Short: "Subscribe to merge request", | ||
Long: ``, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, id, err := parseArgsWithGitBranchMR(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p, err := lab.FindProject(rn) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.MRSubscribe(p.ID, int(id)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Subscribed to merge request !%d\n", id) | ||
}, | ||
} | ||
|
||
func init() { | ||
mrCmd.AddCommand(mrSubscribeCmd) | ||
carapace.Gen(mrSubscribeCmd).PositionalCompletion( | ||
action.Remotes(), | ||
action.MergeRequests(mrList), | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/rsteube/carapace" | ||
"github.com/spf13/cobra" | ||
"github.com/zaquestion/lab/internal/action" | ||
lab "github.com/zaquestion/lab/internal/gitlab" | ||
) | ||
|
||
var mrUnsubscribeCmd = &cobra.Command{ | ||
Use: "unsubscribe [remote] <id>", | ||
Aliases: []string{}, | ||
Short: "Unubscribe from merge request", | ||
Long: ``, | ||
PersistentPreRun: LabPersistentPreRun, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rn, id, err := parseArgsWithGitBranchMR(args) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
p, err := lab.FindProject(rn) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = lab.MRUnsubscribe(p.ID, int(id)) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf("Unsubscribed from merge request !%d\n", id) | ||
}, | ||
} | ||
|
||
func init() { | ||
mrCmd.AddCommand(mrUnsubscribeCmd) | ||
carapace.Gen(mrUnsubscribeCmd).PositionalCompletion( | ||
action.Remotes(), | ||
action.MergeRequests(mrList), | ||
) | ||
} |
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