Parametrise JIRA url

This commit is contained in:
Miguel de la Cruz 2020-03-05 17:38:53 +01:00
parent 788146e1fa
commit ab2e28e29e
4 changed files with 23 additions and 8 deletions

View file

@ -15,21 +15,31 @@ func InitCmd() *cobra.Command {
Run: initCmdF, Run: initCmdF,
} }
cmd.Flags().StringP("url", "u", "", "the jira server URL")
_ = cmd.MarkFlagRequired("url")
cmd.Flags().StringP("project", "p", "", "the jira project key to associate the tickets with") cmd.Flags().StringP("project", "p", "", "the jira project key to associate the tickets with")
_ = cmd.MarkFlagRequired("project") _ = cmd.MarkFlagRequired("project")
cmd.Flags().StringP("epic", "e", "", "the epic id to associate this campaign with") cmd.Flags().StringP("epic", "e", "", "the epic id to associate this campaign with")
_ = cmd.MarkFlagRequired("epic") _ = cmd.MarkFlagRequired("epic")
cmd.Flags().StringP("summary", "s", "", "the summary of the tickets. Can contain the variables {{.Filename}}, {{.LineNo}} and {{.Text}}") cmd.Flags().StringP("summary", "s", "", "the summary of the tickets")
_ = cmd.MarkFlagRequired("summary") _ = cmd.MarkFlagRequired("summary")
return cmd return cmd
} }
func initCmdF(cmd *cobra.Command, _ []string) { func initCmdF(cmd *cobra.Command, _ []string) {
url, _ := cmd.Flags().GetString("url")
project, _ := cmd.Flags().GetString("project") project, _ := cmd.Flags().GetString("project")
epic, _ := cmd.Flags().GetString("epic") epic, _ := cmd.Flags().GetString("epic")
summary, _ := cmd.Flags().GetString("summary") summary, _ := cmd.Flags().GetString("summary")
if err := campaign.Save(&model.Campaign{Project: project, Epic: epic, Summary: summary}); err != nil {
cmp := &model.Campaign{
Url: url,
Project: project,
Epic: epic,
Summary: summary,
}
if err := campaign.Save(cmp); err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
} }

View file

@ -34,6 +34,8 @@ func CreateJiraTicketStandaloneCmd() *cobra.Command {
RunE: createJiraTicketStandaloneCmdF, RunE: createJiraTicketStandaloneCmdF,
} }
cmd.Flags().String("url", "", "the jira server URL")
_ = cmd.MarkFlagRequired("url")
cmd.Flags().String("epic", "", "the jira epic id to associate the ticket with") cmd.Flags().String("epic", "", "the jira epic id to associate the ticket with")
_ = cmd.MarkFlagRequired("epic") _ = cmd.MarkFlagRequired("epic")
cmd.Flags().String("team", "", "the team for the new ticket") cmd.Flags().String("team", "", "the team for the new ticket")
@ -57,6 +59,8 @@ func GetJiraTicketStandaloneCmd() *cobra.Command {
Run: getJiraTicketStandaloneCmdF, Run: getJiraTicketStandaloneCmdF,
} }
cmd.Flags().String("url", "", "the jira server URL")
_ = cmd.MarkFlagRequired("url")
cmd.Flags().String("username", "", "the jira username") cmd.Flags().String("username", "", "the jira username")
cmd.Flags().String("token", "", "the jira token") cmd.Flags().String("token", "", "the jira token")
@ -76,6 +80,7 @@ func getVarMap(vars []string) (map[string]string, error) {
} }
func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error { func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error {
url, _ := cmd.Flags().GetString("url")
epicId, _ := cmd.Flags().GetString("epic") epicId, _ := cmd.Flags().GetString("epic")
team, _ := cmd.Flags().GetString("team") team, _ := cmd.Flags().GetString("team")
username, _ := cmd.Flags().GetString("username") username, _ := cmd.Flags().GetString("username")
@ -125,7 +130,7 @@ func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error {
} }
description := descriptionBytes.String() description := descriptionBytes.String()
jiraClient, err := jira.NewClient(username, token) jiraClient, err := jira.NewClient(url, username, token)
if err != nil { if err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }
@ -140,6 +145,7 @@ func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error {
} }
func getJiraTicketStandaloneCmdF(cmd *cobra.Command, args []string) { func getJiraTicketStandaloneCmdF(cmd *cobra.Command, args []string) {
url, _ := cmd.Flags().GetString("url")
username, _ := cmd.Flags().GetString("username") username, _ := cmd.Flags().GetString("username")
token, _ := cmd.Flags().GetString("token") token, _ := cmd.Flags().GetString("token")
@ -157,7 +163,7 @@ func getJiraTicketStandaloneCmdF(cmd *cobra.Command, args []string) {
} }
} }
jiraClient, err := jira.NewClient(username, token) jiraClient, err := jira.NewClient(url, username, token)
if err != nil { if err != nil {
ErrorAndExit(cmd, err) ErrorAndExit(cmd, err)
} }

View file

@ -4,19 +4,17 @@ import (
jira "gopkg.in/andygrunwald/go-jira.v1" jira "gopkg.in/andygrunwald/go-jira.v1"
) )
const defaultUrl = "https://mattermost.atlassian.net"
type JiraClient struct { type JiraClient struct {
*jira.Client *jira.Client
} }
func NewClient(username, token string) (*JiraClient, error) { func NewClient(url, username, token string) (*JiraClient, error) {
tp := jira.BasicAuthTransport{ tp := jira.BasicAuthTransport{
Username: username, Username: username,
Password: token, Password: token,
} }
client, err := jira.NewClient(tp.Client(), defaultUrl) client, err := jira.NewClient(tp.Client(), url)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -1,6 +1,7 @@
package model package model
type Campaign struct { type Campaign struct {
Url string `json:"url"`
Project string `json:"project"` Project string `json:"project"`
Epic string `json:"epic"` Epic string `json:"epic"`
Summary string `json:"summary"` Summary string `json:"summary"`