Categorygithub.com/hrk-ys/go-jira
modulepackage
1.0.0
Repository: https://github.com/hrk-ys/go-jira.git
Documentation: pkg.go.dev

# README

go-jira

GoDoc Build Status Go Report Card

Go client library for Atlassian JIRA.

Go client library for Atlassian JIRA

Features

  • Authentication (HTTP Basic, OAuth, Session Cookie)
  • Create and receive issues
  • Create and retrieve issue transitions (status updates)
  • Call every API endpoint of the JIRA, even it is not directly implemented in this library

This package is not JIRA API complete (yet), but you can call every API endpoint you want. See Call a not implemented API endpoint how to do this. For all possible API endpoints of JRIA have a look at latest JIRA REST API documentation.

Compatible JIRA versions

This package was tested against JIRA v6.3.4 and v7.1.2.

Installation

It is go gettable

$ go get github.com/andygrunwald/go-jira

(optional) to run unit / example tests:

$ cd $GOPATH/src/github.com/andygrunwald/go-jira
$ go test -v ./...

API

Please have a look at the GoDoc documentation for a detailed API description.

The latest JIRA REST API documentation was the base document for this package.

Examples

Further a few examples how the API can be used. A few more examples are available in the GoDoc examples section.

Get a single issue

Lets retrieve MESOS-3325 from the Apache Mesos project.

package main

import (
	"fmt"
	"github.com/andygrunwald/go-jira"
)

func main() {
	jiraClient, _ := jira.NewClient(nil, "https://issues.apache.org/jira/")
	issue, _, _ := jiraClient.Issue.Get("MESOS-3325", nil)

	fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
	fmt.Printf("Type: %s\n", issue.Fields.Type.Name)
	fmt.Printf("Priority: %s\n", issue.Fields.Priority.Name)

	// MESOS-3325: Running [email protected] in a container causes slave to be lost after a restart
	// Type: Bug
	// Priority: Critical
}

Authenticate with jira

Some actions require an authenticated user.

Authenticate with basic auth

Here is an example with a basic auth authentification.

package main

import (
	"fmt"
	"github.com/andygrunwald/go-jira"
)

func main() {
	jiraClient, err := jira.NewClient(nil, "https://your.jira-instance.com/")
	if err != nil {
		panic(err)
	}
	jiraClient.Authentication.SetBasicAuth("username", "password")

	issue, _, err := jiraClient.Issue.Get("SYS-5156", nil)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
}

Authenticate with session cookie

Here is an example with a session cookie authentification.

package main

import (
	"fmt"
	"github.com/andygrunwald/go-jira"
)

func main() {
	jiraClient, err := jira.NewClient(nil, "https://your.jira-instance.com/")
	if err != nil {
		panic(err)
	}

	res, err := jiraClient.Authentication.AcquireSessionCookie("username", "password")
	if err != nil || res == false {
		fmt.Printf("Result: %v\n", res)
		panic(err)
	}

	issue, _, err := jiraClient.Issue.Get("SYS-5156", nil)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
}

Authenticate with OAuth

If you want to connect via OAuth to your JIRA Cloud instance checkout the example of using OAuth authentication with JIRA in Go by @Lupus.

For more details have a look at the issue #56.

Create an issue

Example how to create an issue.

package main

import (
	"fmt"
	"github.com/andygrunwald/go-jira"
)

func main() {
	jiraClient, err := jira.NewClient(nil, "https://your.jira-instance.com/")
	if err != nil {
		panic(err)
	}

	res, err := jiraClient.Authentication.AcquireSessionCookie("username", "password")
	if err != nil || res == false {
		fmt.Printf("Result: %v\n", res)
		panic(err)
	}

	i := jira.Issue{
		Fields: &jira.IssueFields{
			Assignee: &jira.User{
				Name: "myuser",
			},
			Reporter: &jira.User{
				Name: "youruser",
			},
			Description: "Test Issue",
			Type: jira.IssueType{
				Name: "Bug",
			},
			Project: jira.Project{
				Key: "PROJ1",
			},
			Summary: "Just a demo issue",
		},
	}
	issue, _, err := jiraClient.Issue.Create(&i)
	if err != nil {
		panic(err)
	}

	fmt.Printf("%s: %+v\n", issue.Key, issue.Fields.Summary)
}

Call a not implemented API endpoint

Not all API endpoints of the JIRA API are implemented into go-jira. But you can call them anyway: Lets get all public projects of Atlassian`s JIRA instance.

package main

import (
	"fmt"
	"github.com/andygrunwald/go-jira"
)

func main() {
	jiraClient, _ := jira.NewClient(nil, "https://jira.atlassian.com/")
	req, _ := jiraClient.NewRequest("GET", "/rest/api/2/project", nil)

	projects := new([]jira.Project)
	_, err := jiraClient.Do(req, projects)
	if err != nil {
		panic(err)
	}

	for _, project := range *projects {
		fmt.Printf("%s: %s\n", project.Key, project.Name)
	}

	// ...
	// BAM: Bamboo
	// BAMJ: Bamboo JIRA Plugin
	// CLOV: Clover
	// CONF: Confluence
	// ...
}

Implementations

Code structure

The code structure of this package was inspired by google/go-github.

There is one main part (the client). Based on this main client the other endpoints, like Issues or Authentication are extracted in services. E.g. IssueService or AuthenticationService. These services own a responsibility of the single endpoints / usecases of JIRA.

Contribution

Contribution, in any kind of way, is highly welcome! It doesn't matter if you are not able to write code. Creating issues or holding talks and help other people to use go-jira is contribution, too! A few examples:

  • Correct typos in the README / documentation
  • Reporting bugs
  • Implement a new feature or endpoint
  • Sharing the love if go-jira and help people to get use to it

If you are new to pull requests, checkout Collaborating on projects using issues and pull requests / Creating a pull request.

License

This project is released under the terms of the MIT license.

# Functions

CheckResponse checks the API response for errors, and returns them if present.
InitIssueWithMetaAndFields returns Issue with with values from fieldsConfig properly set.
NewClient returns a new JIRA API client.

# Constants

AssigneeAutomatic represents the value of the "Assignee: Automatic" of JIRA.

# Structs

Attachment represents a JIRA attachment.
AuthenticationService handles authentication for the JIRA instance / API.
AvatarUrls represents different dimensions of avatars / images.
Board represents a JIRA agile board.
BoardListOptions specifies the optional parameters to the BoardService.GetList.
BoardService handles Agile Boards for the JIRA instance / API.
BoardsList reflects a list of agile boards.
Changelog reflects the change log of an issue.
ChangelogHistory reflects one single changelog history entry.
ChangelogItems reflects one single changelog item of a history item.
A Client manages communication with the JIRA API.
Comment represents a comment by a person to an issue in JIRA.
Comments represents a list of Comment.
CommentVisibility represents he visibility of a comment.
Component represents a "component" of a JIRA issue.
CreateMetaInfo contains information about fields and their attributed to create a ticket.
CreateTransitionPayload is used for creating new issue transitions.
Epic represents the epic to which an issue is associated Not that this struct does not process the returned "color" value.
FixVersion represents a software release in which an issue is fixed.
GetQueryOptions specifies the optional parameters for the Get Issue methods.
GroupMember reflects a single member of a group.
GroupService handles Groups for the JIRA instance / API.
Issue represents a JIRA issue.
IssueFields represents single fields of a JIRA issue.
IssueLink represents a link between two issues in JIRA.
IssueLinkType represents a type of a link between to issues in JIRA.
IssueService handles Issues for the JIRA instance / API.
IssuesInSprintResult represents a wrapper struct for search result.
IssuesWrapper represents a wrapper struct for moving issues to sprint.
IssueType represents a type of a JIRA issue.
MetaIssueType represents the different issue types a project has.
MetaProject is the meta information about a project returned from createmeta api.
Option represents an option value in a SelectList or MultiSelect custom issue field.
Parent represents the parent of a JIRA issue, to be used with subtask issue types.
Priority represents a priority of a JIRA issue.
Progress represents the progress of a JIRA issue.
Project represents a JIRA Project.
ProjectCategory represents a single project category.
ProjectComponent represents a single component of a project.
ProjectService handles projects for the JIRA instance / API.
Resolution represents a resolution of a JIRA issue.
Response represents JIRA API response.
SearchOptions specifies the optional parameters to various List methods that support pagination.
Session represents a Session JSON response by the JIRA API.
Sprint represents a sprint on JIRA agile board.
SprintService handles sprints in JIRA Agile API.
Status represents the current status of a JIRA issue.
StatusCategory represents the category a status belongs to.
Subtasks represents all issues of a parent issue.
TimeTracking represents the timetracking fields of a JIRA issue.
Transition represents an issue transition in JIRA.
TransitionField represents the value of one Transition.
TransitionPayload represents the request payload of Transition calls like DoTransition.
User represents a JIRA user.
UserService handles users for the JIRA instance / API.
Version represents a single release version of a project.
Watches represents a type of how many user are "observing" a JIRA issue to track the status / updates.
Worklog represents the work log of a JIRA issue.
WorklogRecord represents one entry of a Worklog.

# Type aliases

CustomFields represents custom fields of JIRA This can heavily differ between JIRA instances.
ProjectList represent a list of Projects.
Time represents the Time definition of JIRA as a time.Time of go.