Compare commits

..

13 Commits

Author SHA1 Message Date
Cory Bennett b98da3612d Updated Changelog 2018-04-15 19:21:10 -07:00
Cory Bennett 7f9595cf15 fix IsTerminal usage for windows 2018-04-15 19:10:29 -07:00
Cory Bennett 09584981b6 version bump 2018-04-15 17:55:00 -07:00
Cory Bennett 1bc6b55b85 Updated Changelog 2018-04-15 17:55:00 -07:00
Cory Bennett d787ac030c [#166] fix issue when editing templates specified with full path 2018-04-15 17:40:22 -07:00
Cory Bennett 09a61c3ea1 only prompt on logout if stdin and stdout are terminals 2018-04-15 17:15:48 -07:00
Cory Bennett 64ce3812a6 only prompt on logout if stdin is an active terminal 2018-04-15 17:07:01 -07:00
Cory Bennett 9146346e2f [#163] fix url path join logic 2018-04-15 16:56:09 -07:00
Cory Bennett e639cce9af [#160] prompt when api-token is invalid to get new token 2018-04-15 15:30:30 -07:00
Cory Bennett 06b26c9e00 [#157] add password-directory: path to allow overriding PASSWORD_STORE_DIR from configs 2018-04-15 13:56:37 -07:00
coryb ac39f9ae1d Merge pull request #161 from vanniktech/patch-1
Add syntax highlighting to YAML blocks in README
2018-04-03 09:28:36 -07:00
Cory Bennett bd3cf994b8 [#160] allow jira logout to delete your api-token from keychain 2018-04-03 09:21:52 -07:00
Niklas Baudy 91059b3578 Add syntax highlighting to YAML blocks in README 2018-04-03 17:45:39 +02:00
36 changed files with 136 additions and 79 deletions
+1
View File
@@ -3,6 +3,7 @@ config:
password-source: pass
endpoint: https://go-jira.atlassian.net
user: admin
login: atlassian@corybennett.org
queries:
todo: |
+10
View File
@@ -1,5 +1,15 @@
# Changelog
## 1.0.17 - 2018-04-15
* fix IsTerminal usage for windows [Cory Bennett] [[7f9595c](https://github.com/Netflix-Skunkworks/go-jira/commit/7f9595c)]
* [[#166](https://github.com/Netflix-Skunkworks/go-jira/issues/166)] fix issue when editing templates specified with full path [Cory Bennett] [[d787ac0](https://github.com/Netflix-Skunkworks/go-jira/commit/d787ac0)]
* only prompt on logout if stdin and stdout are terminals [Cory Bennett] [[09a61c3](https://github.com/Netflix-Skunkworks/go-jira/commit/09a61c3)]
* [[#163](https://github.com/Netflix-Skunkworks/go-jira/issues/163)] fix url path join logic [Cory Bennett] [[9146346](https://github.com/Netflix-Skunkworks/go-jira/commit/9146346)]
* [[#160](https://github.com/Netflix-Skunkworks/go-jira/issues/160)] prompt when api-token is invalid to get new token [Cory Bennett] [[e639cce](https://github.com/Netflix-Skunkworks/go-jira/commit/e639cce)]
* [[#157](https://github.com/Netflix-Skunkworks/go-jira/issues/157)] add `password-directory: path` to allow overriding PASSWORD_STORE_DIR from configs [Cory Bennett] [[06b26c9](https://github.com/Netflix-Skunkworks/go-jira/commit/06b26c9)]
* [[#160](https://github.com/Netflix-Skunkworks/go-jira/issues/160)] allow `jira logout` to delete your api-token from keychain [Cory Bennett] [[bd3cf99](https://github.com/Netflix-Skunkworks/go-jira/commit/bd3cf99)]
## 1.0.16 - 2018-04-01
* [[#159](https://github.com/Netflix-Skunkworks/go-jira/issues/159)] fix `slice bounds out of range` error in `abbrev` template function [Cory Bennett] [[359bec2](https://github.com/Netflix-Skunkworks/go-jira/commit/359bec2)]
+9 -9
View File
@@ -93,7 +93,7 @@ esac
###### **Custom Commands**
Now you can create your own custom commands to do common operations with jira. Please see the details **Custom Commands** section below for more details. If you want to create a command `jira mine` that lists all the issues assigned to you now you can modify your `.jira.d/config.yml` file to add a `custom-commands` section like this:
```
```yaml
custom-commands:
- name: mine
help: display issues assigned to me
@@ -138,7 +138,7 @@ Previously `jira` used attempt to get a `JSESSION` cookies by authenticating wit
The complicated configuration hierarchy is used because **go-jira** attempts to be context aware. For example, if you are working on a "foo" project and you `cd` into your project workspace, wouldn't it be nice if `jira ls` automatically knew to list only issues related to the "foo" project? Likewise when you `cd` to the "bar" project then `jira ls` should only list issues related to "bar" project. You can do this with by creating a configuration under your project workspace at **./.jira.d/config.yml** that looks like:
```
```yaml
project: foo
```
@@ -186,7 +186,7 @@ esac
### Custom Commands
You can now create custom commands for `jira` just by editing your `.jira.d/config.yml` config file. These commands are effectively shell-scripts that can have documented options and arguments. The basic format is like:
```
```yaml
custom-commands:
- command1
- command2
@@ -234,7 +234,7 @@ These are possible keys under the command `args` property:
The `script` property is a template that whould produce `/bin/sh` compatible syntax after the template has been processed. There are 2 key template functions `{{args}}` and `{{options}}` that return the parsed arguments and option flags as a map.
To demonstrate how you might use args and options here is a `custom-test` command:
```
```yaml
custom-commands:
- name: custom-test
help: Testing the custom commands
@@ -285,7 +285,7 @@ COMMAND arg1 --abc short-non-default --day Tuesday more1 more2 more3
```
The script has access to all the environment variables that are in your current environment plus those that `jira` will set. `jira` sets environment variables for each config property it has parsed from `.jira.d/config.yml` or the command configs at `.jira.d/<command>.yml`. It might be useful to see all environment variables that `jira` is producing, so here is a simple custom command to list them:
```
```yaml
custom-commands:
- name: env
help: print the JIRA environment variables available to custom commands
@@ -294,7 +294,7 @@ custom-commands:
```
You could use the environment variables automatically, so if your `.jira.d/config.yml` looks something like this:
```
```yaml
project: PROJECT
custom-commands:
- name: print-project
@@ -305,7 +305,7 @@ custom-commands:
##### Examples
* `jira mine` for listing issues assigned to you
```
```yaml
custom-commands:
- name: mine
help: display issues assigned to me
@@ -319,7 +319,7 @@ custom-commands:
fi
```
* `jira sprint` for listing issues in your current sprint
```
```yaml
custom-commands:
- name: sprint
help: display issues for active sprint
@@ -375,7 +375,7 @@ If your Jira service still allows you to use the Session based authention method
#### User vs Login
The Jira service has sometimes differing opinions about how a user is identified. In other words the ID you login with might not be ID that the jira system recognized you as. This matters when trying to identify a user via various Jira REST APIs (like issue assignment). This is especially relevent when trying to authenticate with an API Token where the authentication user is usually an email address, but within the Jira system the user is identified by a user name. To accomodate this `jira` now supports two different properties in the config file. So when authentication using the API Tokens you will likely want something like this in your `$HOME/.jira.d/config.yml` file:
```
```yaml
user: person
login: person@example.com
```
+2 -4
View File
@@ -1,8 +1,6 @@
package jira
import (
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
)
@@ -12,7 +10,7 @@ func (j *Jira) GetAttachment(id string) (*jiradata.Attachment, error) {
}
func GetAttachment(ua HttpClient, endpoint string, id string) (*jiradata.Attachment, error) {
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id)
uri := URLJoin(endpoint, "rest/api/2/attachment", id)
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -32,7 +30,7 @@ func (j *Jira) RemoveAttachment(id string) error {
}
func RemoveAttachment(ua HttpClient, endpoint string, id string) error {
uri := fmt.Sprintf("%s/rest/api/2/attachment/%s", endpoint, id)
uri := URLJoin(endpoint, "rest/api/2/attachment", id)
resp, err := ua.Delete(uri)
if err != nil {
return err
+1 -2
View File
@@ -3,7 +3,6 @@ package jira
import (
"bytes"
"encoding/json"
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
)
@@ -23,7 +22,7 @@ func CreateComponent(ua HttpClient, endpoint string, cp ComponentProvider) (*jir
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s/rest/api/2/component", endpoint)
uri := URLJoin(endpoint, "rest/api/2/component")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
+3 -3
View File
@@ -23,7 +23,7 @@ func EpicSearch(ua HttpClient, endpoint string, epic string, sp SearchProvider)
// if err != nil {
// return nil, err
// }
uri, err := url.Parse(fmt.Sprintf("%s/rest/agile/1.0/epic/%s/issue", endpoint, epic))
uri, err := url.Parse(URLJoin(endpoint, "rest/agile/1.0/epic", epic, "issue"))
if err != nil {
return nil, err
}
@@ -74,7 +74,7 @@ func EpicAddIssues(ua HttpClient, endpoint string, epic string, eip EpicIssuesPr
return err
}
uri := fmt.Sprintf("%s/rest/agile/1.0/epic/%s/issue", endpoint, epic)
uri := URLJoin(endpoint, "rest/agile/1.0/epic", epic, "issue")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
@@ -99,7 +99,7 @@ func EpicRemoveIssues(ua HttpClient, endpoint string, eip EpicIssuesProvider) er
return err
}
uri := fmt.Sprintf("%s/rest/agile/1.0/epic/none/issue", endpoint)
uri := URLJoin(endpoint, "rest/agile/1.0/epic/none/issue")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
+1 -3
View File
@@ -1,8 +1,6 @@
package jira
import (
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
)
@@ -12,7 +10,7 @@ func (j *Jira) GetFields() ([]jiradata.Field, error) {
}
func GetFields(ua HttpClient, endpoint string) ([]jiradata.Field, error) {
uri := fmt.Sprintf("%s/rest/api/2/field", endpoint)
uri := URLJoin(endpoint, "rest/api/2/field")
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
+26 -20
View File
@@ -59,7 +59,8 @@ func GetIssue(ua HttpClient, endpoint string, issue string, iqg IssueQueryProvid
if iqg != nil {
query = iqg.ProvideIssueQueryString()
}
uri := fmt.Sprintf("%s/rest/api/2/issue/%s%s", endpoint, issue, query)
uri := URLJoin(endpoint, "rest/api/2/issue", issue)
uri += query
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -84,7 +85,8 @@ func GetIssueWorklog(ua HttpClient, endpoint string, issue string) (*jiradata.Wo
maxResults := 100
worklogs := jiradata.Worklogs{}
for startAt < total {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/worklog?startAt=%d&maxResults=%d", endpoint, issue, startAt, maxResults)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "worklog")
uri += fmt.Sprintf("?startAt=%d&maxResults=%d", startAt, maxResults)
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -124,7 +126,7 @@ func AddIssueWorklog(ua HttpClient, endpoint string, issue string, wp WorklogPro
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/worklog", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "worklog")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
@@ -144,7 +146,7 @@ func (j *Jira) GetIssueEditMeta(issue string) (*jiradata.EditMeta, error) {
}
func GetIssueEditMeta(ua HttpClient, endpoint string, issue string) (*jiradata.EditMeta, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/editmeta", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "editmeta")
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -173,7 +175,7 @@ func EditIssue(ua HttpClient, endpoint string, issue string, iup IssueUpdateProv
if err != nil {
return err
}
uri := fmt.Sprintf("%s/rest/api/2/issue/%s", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue)
resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
@@ -197,7 +199,7 @@ func CreateIssue(ua HttpClient, endpoint string, iup IssueUpdateProvider) (*jira
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s/rest/api/2/issue", endpoint)
uri := URLJoin(endpoint, "rest/api/2/issue")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
@@ -217,7 +219,8 @@ func (j *Jira) GetIssueCreateMetaProject(projectKey string) (*jiradata.CreateMet
}
func GetIssueCreateMetaProject(ua HttpClient, endpoint string, projectKey string) (*jiradata.CreateMetaProject, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s&expand=projects.issuetypes.fields", endpoint, projectKey)
uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
uri += fmt.Sprintf("?projectKeys=%s&expand=projects.issuetypes.fields", projectKey)
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -246,7 +249,8 @@ func (j *Jira) GetIssueCreateMetaIssueType(projectKey, issueTypeName string) (*j
}
func GetIssueCreateMetaIssueType(ua HttpClient, endpoint string, projectKey, issueTypeName string) (*jiradata.IssueType, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/createmeta?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", endpoint, projectKey, url.QueryEscape(issueTypeName))
uri := URLJoin(endpoint, "rest/api/2/issue/createmeta")
uri += fmt.Sprintf("?projectKeys=%s&issuetypeNames=%s&expand=projects.issuetypes.fields", projectKey, url.QueryEscape(issueTypeName))
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -288,7 +292,7 @@ func LinkIssues(ua HttpClient, endpoint string, lip LinkIssueProvider) error {
if err != nil {
return err
}
uri := fmt.Sprintf("%s/rest/api/2/issueLink", endpoint)
uri := URLJoin(endpoint, "rest/api/2/issueLink")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
@@ -307,7 +311,8 @@ func (j *Jira) GetIssueTransitions(issue string) (*jiradata.TransitionsMeta, err
}
func GetIssueTransitions(ua HttpClient, endpoint string, issue string) (*jiradata.TransitionsMeta, error) {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions?expand=transitions.fields", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "transitions")
uri += "?expand=transitions.fields"
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -332,7 +337,7 @@ func TransitionIssue(ua HttpClient, endpoint string, issue string, iup IssueUpda
if err != nil {
return err
}
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/transitions", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "transitions")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
@@ -351,7 +356,7 @@ func (j *Jira) GetIssueLinkTypes() (*jiradata.IssueLinkTypes, error) {
}
func GetIssueLinkTypes(ua HttpClient, endpoint string) (*jiradata.IssueLinkTypes, error) {
uri := fmt.Sprintf("%s/rest/api/2/issueLinkType", endpoint)
uri := URLJoin(endpoint, "rest/api/2/issueLinkType")
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -375,7 +380,7 @@ func (j *Jira) IssueAddVote(issue string) error {
}
func IssueAddVote(ua HttpClient, endpoint string, issue string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/votes", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "votes")
resp, err := ua.Post(uri, "application/json", strings.NewReader("{}"))
if err != nil {
return err
@@ -394,7 +399,7 @@ func (j *Jira) IssueRemoveVote(issue string) error {
}
func IssueRemoveVote(ua HttpClient, endpoint string, issue string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/votes", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "votes")
resp, err := ua.Delete(uri)
if err != nil {
return err
@@ -422,7 +427,7 @@ func RankIssues(ua HttpClient, endpoint string, rrp RankRequestProvider) error {
if err != nil {
return err
}
uri := fmt.Sprintf("%s/rest/agile/1.0/issue/rank", endpoint)
uri := URLJoin(endpoint, "rest/agile/1.0/issue/rank")
resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
@@ -441,7 +446,7 @@ func (j *Jira) IssueAddWatcher(issue, user string) error {
}
func IssueAddWatcher(ua HttpClient, endpoint string, issue, user string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/watchers", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "watchers")
resp, err := ua.Post(uri, "application/json", strings.NewReader(fmt.Sprintf("%q", user)))
if err != nil {
return err
@@ -460,7 +465,8 @@ func (j *Jira) IssueRemoveWatcher(issue, user string) error {
}
func IssueRemoveWatcher(ua HttpClient, endpoint string, issue, user string) error {
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/watchers?username=%s", endpoint, issue, user)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "watchers")
uri += fmt.Sprintf("?username=%s", user)
resp, err := ua.Delete(uri)
if err != nil {
return err
@@ -488,7 +494,7 @@ func IssueAddComment(ua HttpClient, endpoint string, issue string, cp CommentPro
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/comment", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "comment")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
@@ -526,7 +532,7 @@ func IssueAssign(ua HttpClient, endpoint string, issue, name string) error {
if err != nil {
return err
}
uri := fmt.Sprintf("%s/rest/api/2/issue/%s/assignee", endpoint, issue)
uri := URLJoin(endpoint, "rest/api/2/issue", issue, "assignee")
resp, err := ua.Put(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return err
@@ -556,7 +562,7 @@ func IssueAttachFile(ua HttpClient, endpoint string, issue, filename string, con
return nil, err
}
uri, err := url.Parse(fmt.Sprintf("%s/rest/api/2/issue/%s/attachments", endpoint, issue))
uri, err := url.Parse(URLJoin(endpoint, "rest/api/2/issue", issue, "attachments"))
req := oreo.RequestBuilder(uri).WithMethod("POST").WithHeader(
"X-Atlassian-Token", "no-check",
).WithHeader(
+1 -1
View File
@@ -7,7 +7,7 @@ import (
var log = logging.MustGetLogger("jira")
const VERSION = "1.0.16"
const VERSION = "1.0.17"
type Jira struct {
Endpoint string `json:"endpoint,omitempty" yaml:"endpoint,omitempty"`
+4
View File
@@ -33,6 +33,7 @@ type GlobalOptions struct {
Insecure figtree.BoolOption `yaml:"insecure,omitempty" json:"insecure,omitempty"`
Login figtree.StringOption `yaml:"login,omitempty" json:"login,omitempty"`
PasswordSource figtree.StringOption `yaml:"password-source,omitempty" json:"password-source,omitempty"`
PasswordDirectory figtree.StringOption `yaml:"password-directory,omitempty" json:"password-directory,omitempty"`
Quiet figtree.BoolOption `yaml:"quiet,omitempty" json:"quiet,omitempty"`
SocksProxy figtree.StringOption `yaml:"socksproxy,omitempty" json:"socksproxy,omitempty"`
UnixProxy figtree.StringOption `yaml:"unixproxy,omitempty" json:"unixproxy,omitempty"`
@@ -122,6 +123,9 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
// rerun the original request
return o.Do(req)
}
} else if globals.AuthMethod() == "api-token" && resp.StatusCode == 401 {
globals.SetPass("")
return o.Do(req)
}
return resp, nil
},
+10
View File
@@ -40,6 +40,11 @@ func (o *GlobalOptions) GetPass() string {
panic(err)
}
} else if o.PasswordSource.Value == "pass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
os.Setenv("PASSWORD_STORE_DIR", o.PasswordDirectory.Value)
defer os.Setenv("PASSWORD_STORE_DIR", orig)
}
if bin, err := exec.LookPath("pass"); err == nil {
buf := bytes.NewBufferString("")
cmd := exec.Command(bin, o.keyName())
@@ -95,6 +100,11 @@ func (o *GlobalOptions) SetPass(passwd string) error {
return err
}
} else if o.PasswordSource.Value == "pass" {
if o.PasswordDirectory.Value != "" {
orig := os.Getenv("PASSWORD_STORE_DIR")
os.Setenv("PASSWORD_STORE_DIR", o.PasswordDirectory.Value)
defer os.Setenv("PASSWORD_STORE_DIR", orig)
}
if bin, err := exec.LookPath("pass"); err == nil {
log.Debugf("using %s", bin)
passName := o.keyName()
+2 -1
View File
@@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"time"
@@ -30,7 +31,7 @@ func findClosestParentPath(fileName string) (string, error) {
}
func tmpYml(tmpFilePrefix string) (*os.File, error) {
fh, err := ioutil.TempFile("", tmpFilePrefix)
fh, err := ioutil.TempFile("", filepath.Base(tmpFilePrefix))
if err != nil {
return nil, err
}
+1 -1
View File
@@ -52,7 +52,7 @@ func CmdAssign(o *oreo.Client, globals *jiracli.GlobalOptions, opts *AssignOptio
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
+2 -2
View File
@@ -66,8 +66,8 @@ func CmdBlock(o *oreo.Client, globals *jiracli.GlobalOptions, opts *BlockOptions
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
}
if opts.Browse.Value {
+2 -3
View File
@@ -1,11 +1,10 @@
package jiracmd
import (
"fmt"
"github.com/coryb/figtree"
"github.com/coryb/oreo"
"github.com/pkg/browser"
jira "gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
@@ -27,5 +26,5 @@ func CmdBrowseRegistry() *jiracli.CommandRegistryEntry {
// CmdBrowse open the default system browser to the provided issue
func CmdBrowse(globals *jiracli.GlobalOptions, issue string) error {
return browser.OpenURL(fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issue))
return browser.OpenURL(jira.URLJoin(globals.Endpoint.Value, "browse", issue))
}
+1 -1
View File
@@ -68,7 +68,7 @@ func CmdComment(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CommentOpt
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
+3 -2
View File
@@ -93,8 +93,9 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
return err
}
browseLink := jira.URLJoin(globals.Endpoint.Value, "browse", issueResp.Key)
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key)
fmt.Printf("OK %s %s\n", issueResp.Key, browseLink)
}
if opts.SaveFile != "" {
@@ -105,7 +106,7 @@ func CmdCreate(o *oreo.Client, globals *jiracli.GlobalOptions, opts *CreateOptio
defer fh.Close()
out, err := yaml.Marshal(map[string]string{
"issue": issueResp.Key,
"link": fmt.Sprintf("%s/browse/%s", globals.Endpoint.Value, issueResp.Key),
"link": browseLink,
})
if err != nil {
return err
+2 -2
View File
@@ -67,7 +67,7 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
}
meta, err := jira.GetIssueTransitions(o, globals.Endpoint.Value, opts.InwardIssue.Key)
@@ -103,7 +103,7 @@ func CmdDup(o *oreo.Client, globals *jiracli.GlobalOptions, opts *DupOptions) er
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
}
if opts.Browse.Value {
+2 -2
View File
@@ -98,7 +98,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
@@ -145,7 +145,7 @@ func CmdEdit(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EditOptions)
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key)
fmt.Printf("OK %s %s\n", issueData.Key, jira.URLJoin(globals.Endpoint.Value, "browse", issueData.Key))
}
if opts.Browse.Value {
return CmdBrowse(globals, issueData.Key)
+2 -2
View File
@@ -44,9 +44,9 @@ func CmdEpicAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EpicAddOpt
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Epic, globals.Endpoint.Value, opts.Epic)
fmt.Printf("OK %s %s\n", opts.Epic, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Epic))
for _, issue := range opts.Issues {
fmt.Printf("OK %s %s/browse/%s\n", issue, globals.Endpoint.Value, issue)
fmt.Printf("OK %s %s\n", issue, jira.URLJoin(globals.Endpoint.Value, "browse", issue))
}
}
+1 -1
View File
@@ -43,7 +43,7 @@ func CmdEpicRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *EpicRem
if !globals.Quiet.Value {
for _, issue := range opts.Issues {
fmt.Printf("OK %s %s/browse/%s\n", issue, globals.Endpoint.Value, issue)
fmt.Printf("OK %s %s\n", issue, jira.URLJoin(globals.Endpoint.Value, "browse", issue))
}
}
+2 -2
View File
@@ -62,8 +62,8 @@ func CmdIssueLink(o *oreo.Client, globals *jiracli.GlobalOptions, opts *IssueLin
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.InwardIssue.Key, globals.Endpoint.Value, opts.InwardIssue.Key)
fmt.Printf("OK %s %s/browse/%s\n", opts.OutwardIssue.Key, globals.Endpoint.Value, opts.OutwardIssue.Key)
fmt.Printf("OK %s %s\n", opts.InwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.InwardIssue.Key))
fmt.Printf("OK %s %s\n", opts.OutwardIssue.Key, jira.URLJoin(globals.Endpoint.Value, "browse", opts.OutwardIssue.Key))
}
if opts.Browse.Value {
+1 -1
View File
@@ -57,7 +57,7 @@ func CmdLabelsAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsAd
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
+1 -1
View File
@@ -58,7 +58,7 @@ func CmdLabelsRemove(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Label
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
+1 -1
View File
@@ -55,7 +55,7 @@ func CmdLabelsSet(o *oreo.Client, globals *jiracli.GlobalOptions, opts *LabelsSe
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
+21
View File
@@ -2,10 +2,13 @@ package jiracmd
import (
"fmt"
"os"
"github.com/coryb/figtree"
"github.com/coryb/oreo"
"github.com/mgutz/ansi"
"golang.org/x/crypto/ssh/terminal"
survey "gopkg.in/AlecAivazis/survey.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiracli"
kingpin "gopkg.in/alecthomas/kingpin.v2"
@@ -29,6 +32,24 @@ func CmdLogoutRegistry() *jiracli.CommandRegistryEntry {
func CmdLogout(o *oreo.Client, globals *jiracli.GlobalOptions, opts *jiracli.CommonOptions) error {
if globals.AuthMethod() == "api-token" {
log.Noticef("No need to logout when using api-token authentication method")
if globals.GetPass() != "" && terminal.IsTerminal(int(os.Stdin.Fd())) && terminal.IsTerminal(int(os.Stdout.Fd())) {
delete := false
err := survey.AskOne(
&survey.Confirm{
Message: fmt.Sprintf("Delete api-token from password provider [%s]: ", globals.PasswordSource),
Default: false,
},
&delete,
nil,
)
if err != nil {
log.Errorf("%s", err)
panic(jiracli.Exit{Code: 1})
}
if delete {
globals.SetPass("")
}
}
return nil
}
ua := o.WithoutRedirect().WithRetries(0).WithoutCallbacks()
+2 -2
View File
@@ -59,8 +59,8 @@ func CmdRank(o *oreo.Client, globals *jiracli.GlobalOptions, opts *RankOptions)
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.First, globals.Endpoint.Value, opts.First)
fmt.Printf("OK %s %s/browse/%s\n", opts.Second, globals.Endpoint.Value, opts.Second)
fmt.Printf("OK %s %s\n", opts.First, jira.URLJoin(globals.Endpoint.Value, "browse", opts.First))
fmt.Printf("OK %s %s\n", opts.Second, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Second))
}
if opts.Browse.Value {
+1 -1
View File
@@ -108,7 +108,7 @@ func CmdSubtask(o *oreo.Client, globals *jiracli.GlobalOptions, opts *SubtaskOpt
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueResp.Key, globals.Endpoint.Value, issueResp.Key)
fmt.Printf("OK %s %s\n", issueResp.Key, jira.URLJoin(globals.Endpoint.Value, "browse", issueResp.Key))
}
if opts.Browse.Value {
+1 -1
View File
@@ -157,7 +157,7 @@ func CmdTransition(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Transit
return jiracli.CliError(err)
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", issueData.Key, globals.Endpoint.Value, issueData.Key)
fmt.Printf("OK %s %s\n", issueData.Key, jira.URLJoin(globals.Endpoint.Value, "browse", issueData.Key))
}
if opts.Browse.Value {
+1 -1
View File
@@ -64,7 +64,7 @@ func CmdVote(o *oreo.Client, globals *jiracli.GlobalOptions, opts *VoteOptions)
}
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
+1 -1
View File
@@ -71,7 +71,7 @@ func CmdWatch(o *oreo.Client, globals *jiracli.GlobalOptions, opts *WatchOptions
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
+1 -1
View File
@@ -59,7 +59,7 @@ func CmdWorklogAdd(o *oreo.Client, globals *jiracli.GlobalOptions, opts *Worklog
return err
}
if !globals.Quiet.Value {
fmt.Printf("OK %s %s/browse/%s\n", opts.Issue, globals.Endpoint.Value, opts.Issue)
fmt.Printf("OK %s %s\n", opts.Issue, jira.URLJoin(globals.Endpoint.Value, "browse", opts.Issue))
}
if opts.Browse.Value {
return CmdBrowse(globals, opts.Issue)
+1 -3
View File
@@ -1,8 +1,6 @@
package jira
import (
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
)
@@ -12,7 +10,7 @@ func (j *Jira) GetProjectComponents(project string) (*jiradata.Components, error
}
func GetProjectComponents(ua HttpClient, endpoint string, project string) (*jiradata.Components, error) {
uri := fmt.Sprintf("%s/rest/api/2/project/%s/components", endpoint, project)
uri := URLJoin(endpoint, "rest/api/2/project", project, "components")
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
+1 -1
View File
@@ -83,7 +83,7 @@ func Search(ua HttpClient, endpoint string, sp SearchProvider) (*jiradata.Search
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s/rest/api/2/search", endpoint)
uri := URLJoin(endpoint, "rest/api/2/search")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
+3 -4
View File
@@ -3,7 +3,6 @@ package jira
import (
"bytes"
"encoding/json"
"fmt"
"gopkg.in/Netflix-Skunkworks/go-jira.v1/jiradata"
)
@@ -35,7 +34,7 @@ func NewSession(ua HttpClient, endpoint string, ap AuthProvider) (*jiradata.Auth
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s/rest/auth/1/session", endpoint)
uri := URLJoin(endpoint, "rest/auth/1/session")
resp, err := ua.Post(uri, "application/json", bytes.NewBuffer(encoded))
if err != nil {
return nil, err
@@ -55,7 +54,7 @@ func (j *Jira) GetSession() (*jiradata.CurrentUser, error) {
}
func GetSession(ua HttpClient, endpoint string) (*jiradata.CurrentUser, error) {
uri := fmt.Sprintf("%s/rest/auth/1/session", endpoint)
uri := URLJoin(endpoint, "rest/auth/1/session")
resp, err := ua.GetJSON(uri)
if err != nil {
return nil, err
@@ -75,7 +74,7 @@ func (j *Jira) DeleteSession() error {
}
func DeleteSession(ua HttpClient, endpoint string) error {
uri := fmt.Sprintf("%s/rest/auth/1/session", endpoint)
uri := URLJoin(endpoint, "rest/auth/1/session")
resp, err := ua.Delete(uri)
if err != nil {
return err
+12
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"io"
"io/ioutil"
"net/url"
"path"
)
func readJSON(input io.Reader, data interface{}) error {
@@ -21,3 +23,13 @@ func readJSON(input io.Reader, data interface{}) error {
}
return nil
}
func URLJoin(endpoint string, paths ...string) string {
u, err := url.Parse(endpoint)
if err != nil {
panic(fmt.Errorf("Unable to parse endpoint: %s", endpoint))
}
paths = append([]string{u.Path}, paths...)
u.Path = path.Join(paths...)
return u.String()
}