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,
}
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.MarkFlagRequired("project")
cmd.Flags().StringP("epic", "e", "", "the epic id to associate this campaign with")
_ = 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")
return cmd
}
func initCmdF(cmd *cobra.Command, _ []string) {
url, _ := cmd.Flags().GetString("url")
project, _ := cmd.Flags().GetString("project")
epic, _ := cmd.Flags().GetString("epic")
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)
}
}

View file

@ -34,6 +34,8 @@ func CreateJiraTicketStandaloneCmd() *cobra.Command {
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.MarkFlagRequired("epic")
cmd.Flags().String("team", "", "the team for the new ticket")
@ -57,6 +59,8 @@ func GetJiraTicketStandaloneCmd() *cobra.Command {
Run: getJiraTicketStandaloneCmdF,
}
cmd.Flags().String("url", "", "the jira server URL")
_ = cmd.MarkFlagRequired("url")
cmd.Flags().String("username", "", "the jira username")
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 {
url, _ := cmd.Flags().GetString("url")
epicId, _ := cmd.Flags().GetString("epic")
team, _ := cmd.Flags().GetString("team")
username, _ := cmd.Flags().GetString("username")
@ -125,7 +130,7 @@ func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error {
}
description := descriptionBytes.String()
jiraClient, err := jira.NewClient(username, token)
jiraClient, err := jira.NewClient(url, username, token)
if err != nil {
ErrorAndExit(cmd, err)
}
@ -140,6 +145,7 @@ func createJiraTicketStandaloneCmdF(cmd *cobra.Command, _ []string) error {
}
func getJiraTicketStandaloneCmdF(cmd *cobra.Command, args []string) {
url, _ := cmd.Flags().GetString("url")
username, _ := cmd.Flags().GetString("username")
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 {
ErrorAndExit(cmd, err)
}

View file

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

View file

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