go-jira / jira

simple jira command line client in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"jira list ..." encounters "ERROR Invalid Usage: invalid character '<' looking for beginning of value"

thearifismail opened this issue · comments

I am trying to write some go code to fetch JIRA issues from our internal JIRA deployment. No such problem is encountered when using Python. I am very new to "GO" and thinking running Jira query should provide an easy ramp. Hopefully someone can spot the mistake I am making.

The error is the same when I did the following. The actual project name has been replaced by <PROJECT_NAME> in this submission:

  1. Built JIRA locally by cloning this repo
  2. Downloaded a pre-built binary from release web page
  3. Used jira custom command, like jira search
  4. jira list --query="project=<PROJECT_NAME> AND resolution = Unresolved AND assignee = currentUser()"
  5. jira list --query="resolution+=+Unresolved+AND+assignee+=+currentUser()" . This query was provided by Firefox's "Web Developer Tools"
  6. jira list --template table --query="project=<PROJECT_NAME> AND resolution = Unresolved AND assignee = currentUser()"

The project name is specified in ~/.jira.d/config.yml and using JIRA_API_TOKEN because of authentication-method: api-token.

Here is ~/.jira.d/config.yml:

endpoint: https://issues.redhat.com/
user: aarif@redhat.com
authentication-method: api-token
project: <PROJECT_NAME>
custom-commands:
  - name: print-project
    help: print the JIRA environment variables available to custom commands
    script: |
      echo $JIRA_PROJECT
  - name: search
    help: list bugs based on the query provided 
    script: |
      {{jira}} list --template table --query="resolution+=+Unresolved+AND+assignee+=+currentUser()" 

Here is the full console output for the commands provided above:

$ jira list --template table --query="resolution = Unresolved AND assignee = currentUser()"
usage: jira list [<flags>]
alias: jira ls [<flags>]

Prints list of issues for given search criteria

Global flags:
  -h, --help                   Show context-sensitive help (also try --help-long and --help-man).
  -v, --verbose ...            Increase verbosity for debugging
  -e, --endpoint=ENDPOINT      Base URI to use for Jira
  -k, --insecure               Disable TLS certificate verification
  -Q, --quiet                  Suppress output to console
      --unixproxy=UNIXPROXY    Path for a unix-socket proxy
      --socksproxy=SOCKSPROXY  Address for a socks proxy
  -u, --user=USER              user name used within the Jira service
      --login=LOGIN            login name that corresponds to the user used for authentication

Optional flags:
  -t, --template=TEMPLATE        Template to use for output
      --gjq=GJQ                  GJSON Query to filter output, see https://goo.gl/iaYwJ5
  -a, --assignee=ASSIGNEE        User assigned the issue
  -c, --component=COMPONENT      Component to search for
  -i, --issuetype=ISSUETYPE      Issue type to search for
  -l, --limit=LIMIT              Maximum number of results to return in search
  -p, --project=PROJECT          Project to search for
  -n, --named-query=NAMED-QUERY  The name of a query in the `queries` configuration
  -q, --query=QUERY              Jira Query Language (JQL) expression for the search
  -f, --queryfields=QUERYFIELDS  Fields that are used in "list" template
  -r, --reporter=REPORTER        Reporter to search for
  -S, --status=STATUS            Filter on issue status
  -s, --sort=SORT                Sort order to return
  -w, --watcher=WATCHER          Watcher to search for

ERROR Invalid Usage: invalid character '<' looking for beginning of value
$

I tried to follow the information provided in issue #250 but no success yet.

This problem is authentication failure, which is very likely is being caused by mixup of how user, username, login, password, and/ or api-token should be used.

I hit this myself yesterday. Add three --verbose arguments into the command line so you see the HTTP interactions. You'll be seeing a HTML unauthorised response probably like this:

<html>

<head>
    <title>Unauthorized (401)</title>

The invalid character '<' looking for beginning of value is it choking in the HTML stream.

I'm successfully using PAT tokens (authentication-method: bearer-token) with issues.redhat.com but I needed to build from source (main) to pick up changes that include the support.

HTH