Top Related Projects
simple jira command line client in Go
Go library for accessing the GitHub v3 API
GitLab Go SDK
Go Twitter REST and Streaming API v1.1
Quick Overview
go-jira is a Go client library for interacting with Atlassian's JIRA issue tracking system. It provides a convenient way to access JIRA's REST API, allowing developers to integrate JIRA functionality into their Go applications.
Pros
- Comprehensive coverage of JIRA API endpoints
- Well-documented with clear examples
- Actively maintained and regularly updated
- Supports both cloud and self-hosted JIRA instances
Cons
- Limited built-in error handling, requiring additional error checks in client code
- Some advanced JIRA features may not be fully supported
- Dependency on external libraries for authentication and HTTP requests
Code Examples
- Creating a new JIRA client:
jiraClient, err := jira.NewClient(nil, "https://your-jira-instance.atlassian.net")
if err != nil {
log.Fatal(err)
}
- Retrieving an issue:
issue, _, err := jiraClient.Issue.Get("PROJ-123", nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Issue: %s - %s\n", issue.Key, issue.Fields.Summary)
- Creating a new issue:
i := jira.Issue{
Fields: &jira.IssueFields{
Project: jira.Project{Key: "PROJ"},
Type: jira.IssueType{Name: "Bug"},
Summary: "Test issue",
Description: "This is a test issue created using go-jira",
},
}
newIssue, _, err := jiraClient.Issue.Create(&i)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created issue: %s\n", newIssue.Key)
Getting Started
To use go-jira in your Go project, follow these steps:
-
Install the library:
go get github.com/andygrunwald/go-jira
-
Import the library in your Go code:
import "github.com/andygrunwald/go-jira"
-
Create a new JIRA client:
jiraClient, err := jira.NewClient(nil, "https://your-jira-instance.atlassian.net") if err != nil { log.Fatal(err) }
-
Authenticate using your preferred method (e.g., basic auth, OAuth, or personal access token).
-
Start using the client to interact with JIRA API endpoints.
Competitor Comparisons
simple jira command line client in Go
Pros of jira
- More actively maintained with recent updates and contributions
- Broader API coverage, including additional Jira features and endpoints
- Better documentation and examples for various use cases
Cons of jira
- Slightly more complex API structure, which may require a steeper learning curve
- Less stable API, with potential breaking changes between versions
Code Comparison
go-jira/jira:
jiraClient, _ := jira.NewClient(tp, "https://your-domain.atlassian.net/")
issue, _, _ := jiraClient.Issue.Get("ISSUE-KEY", nil)
andygrunwald/go-jira:
jiraClient, _ := jira.NewClient(nil, "https://your-domain.atlassian.net/")
issue, _, _ := jiraClient.Issue.Get("ISSUE-KEY", nil)
Both libraries offer similar basic functionality for interacting with Jira. The main difference lies in the client initialization, where go-jira/jira uses a transport parameter (tp) for authentication, while andygrunwald/go-jira uses a nil value and handles authentication separately.
go-jira/jira provides more extensive features and better maintenance, making it a preferred choice for complex Jira integrations. However, andygrunwald/go-jira may be suitable for simpler use cases or projects requiring a more stable API.
Go library for accessing the GitHub v3 API
Pros of go-github
- More comprehensive API coverage, supporting a wider range of GitHub features
- Better documentation and examples, making it easier for developers to use
- More active development and maintenance, with frequent updates and bug fixes
Cons of go-github
- Larger codebase and more dependencies, potentially increasing complexity
- Focused solely on GitHub, limiting its use for other platforms or services
- May require more frequent updates to keep up with GitHub API changes
Code Comparison
go-github:
client := github.NewClient(nil)
repo, _, err := client.Repositories.Get(context.Background(), "google", "go-github")
go-jira:
jiraClient, _ := jira.NewClient(nil, "https://your-domain.atlassian.net")
issue, _, err := jiraClient.Issue.Get("PROJ-1", nil)
Both libraries provide similar client initialization patterns, but go-github is more GitHub-specific, while go-jira offers flexibility for different Jira instances.
GitLab Go SDK
Pros of go-gitlab
- More comprehensive API coverage for GitLab features
- Better documentation and examples
- More active development and frequent updates
Cons of go-gitlab
- Larger codebase, potentially more complex to use
- Specific to GitLab, less versatile for other project management tools
Code Comparison
go-gitlab:
client, err := gitlab.NewClient("yourtokenhere")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
projects, _, err := client.Projects.ListProjects(&gitlab.ListProjectsOptions{})
go-jira:
tp := jira.BasicAuthTransport{
Username: "username",
Password: "password",
}
client, err := jira.NewClient(tp.Client(), "https://your-domain.atlassian.net")
issue, _, err := client.Issue.Get("ISSUE-KEY", nil)
Both libraries provide similar functionality for their respective platforms, with go-gitlab offering more GitLab-specific features and go-jira focusing on Jira's issue tracking system. The code examples demonstrate the initialization process and a basic API call for each library. go-gitlab uses a token-based authentication, while go-jira shows basic auth in this example.
Go Twitter REST and Streaming API v1.1
Pros of go-twitter
- More comprehensive API coverage for Twitter's endpoints
- Better documentation and examples for various use cases
- Active development and maintenance with frequent updates
Cons of go-twitter
- More complex setup and configuration required
- Steeper learning curve for beginners
- Limited to Twitter-specific functionality
Code Comparison
go-twitter:
config := oauth1.NewConfig("consumerKey", "consumerSecret")
token := oauth1.NewToken("accessToken", "accessSecret")
httpClient := config.Client(oauth1.NoContext, token)
client := twitter.NewClient(httpClient)
tweets, _, err := client.Timelines.HomeTimeline(&twitter.HomeTimelineParams{
Count: 20,
})
go-jira:
tp := jira.BasicAuthTransport{
Username: "username",
Password: "password",
}
client, err := jira.NewClient(tp.Client(), "https://your-domain.atlassian.net")
issue, _, err := client.Issue.Get("ISSUE-KEY", nil)
Both libraries provide client-based interactions with their respective APIs. go-twitter requires OAuth configuration, while go-jira uses basic authentication. go-twitter's example demonstrates retrieving timeline data, whereas go-jira's example shows fetching a specific issue. The setup process for go-twitter is slightly more involved due to OAuth requirements.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
go-jira
Go client library for Atlassian Jira.
:warning: State of this library :warning:
v2 of this library is in development. v2 will contain breaking changes :warning: The current main branch contains the development version of v2.
The goals of v2 are:
- idiomatic go usage
- proper documentation
- being compliant with different kinds of Atlassian Jira products (on-premise vs. cloud)
- remove flaws introduced during the early times of this library
See our milestone Road to v2 and provide feedback in Development is kicking: Road to v2 ð #489.
Attention: The current main
branch represents the v2 development version - we treat this version as unstable and breaking changes are expected.
If you want to stay more stable, please use v1.* - See our releases. Latest stable release: v1.16.0
Features
- Authentication (HTTP Basic, OAuth, Session Cookie, Bearer (for PATs))
- Create and retrieve issues
- Create and retrieve issue transitions (status updates)
- Call every API endpoint of the Jira, even if 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 Jira have a look at latest Jira REST API documentation.
Requirements
- Go >= 1.14
- Jira v6.3.4 & v7.1.2.
Note that we also run our tests against 1.13, though only the last two versions of Go are officially supported.
Installation
It is go gettable
go get github.com/andygrunwald/go-jira
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"
jira "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 mesos-slave@0.23 in a container causes slave to be lost after a restart
// Type: Bug
// Priority: Critical
}
Authentication
The go-jira
library does not handle most authentication directly. Instead, authentication should be handled within
an http.Client
. That client can then be passed into the NewClient
function when creating a jira client.
For convenience, capability for basic and cookie-based authentication is included in the main library.
Token (Jira on Atlassian Cloud)
Token-based authentication uses the basic authentication scheme, with a user-generated API token in place of a user's password. You can generate a token for your user here. Additional information about Atlassian Cloud API tokens can be found here.
A more thorough, runnable example is provided in the examples directory.
func main() {
tp := jira.BasicAuthTransport{
Username: "<username>",
APIToken: "<api-token>",
}
client, err := jira.NewClient(tp.Client(), "https://my.jira.com")
u, _, err = client.User.GetCurrentUser(context.Background())
fmt.Printf("Email: %v\n", u.EmailAddress)
fmt.Println("Success!")
}
Bearer - Personal Access Tokens (self-hosted Jira)
For self-hosted Jira (v8.14 and later), Personal Access Tokens (PATs) were introduced. Similar to the API tokens, PATs are a safe alternative to using username and password for authentication with scripts and integrations. PATs use the Bearer authentication scheme. Read more about Jira PATs here.
See examples/bearerauth for how to use the Bearer authentication scheme with Jira in Go.
Basic (self-hosted Jira)
Password-based API authentication works for self-hosted Jira only, and has been deprecated for users of Atlassian Cloud.
Depending on your version of Jira, either of the above token authentication examples may be used, substituting a user's password for a generated token.
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() {
base := "https://my.jira.com"
tp := jira.BasicAuthTransport{
Username: "username",
Password: "token",
}
jiraClient, err := jira.NewClient(tp.Client(), base)
if err != nil {
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)
}
Change an issue status
This is how one can change an issue status. In this example, we change the issue from "To Do" to "In Progress."
package main
import (
"fmt"
"github.com/andygrunwald/go-jira"
)
func main() {
testIssueID := "FART-1"
base := "https://my.jira.com"
tp := jira.BasicAuthTransport{
Username: "username",
Password: "token",
}
jiraClient, err := jira.NewClient(tp.Client(), base)
if err != nil {
panic(err)
}
issue, _, _ := jiraClient.Issue.Get(testIssueID, nil)
currentStatus := issue.Fields.Status.Name
fmt.Printf("Current status: %s\n", currentStatus)
var transitionID string
possibleTransitions, _, _ := jiraClient.Issue.GetTransitions(testIssueID)
for _, v := range possibleTransitions {
if v.Name == "In Progress" {
transitionID = v.ID
break
}
}
jiraClient.Issue.DoTransition(testIssueID, transitionID)
issue, _, _ = jiraClient.Issue.Get(testIssueID, nil)
fmt.Printf("Status after transition: %+v\n", issue.Fields.Status.Name)
}
Get all the issues for JQL with Pagination
Jira API has limit on maxResults it can return. You may have a usecase where you need to get all issues for given JQL. This example shows reference implementation of GetAllIssues function which does pagination on Jira API to get all the issues for given JQL.
Please look at Pagination Example
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() {
base := "https://my.jira.com"
tp := jira.BasicAuthTransport{
Username: "username",
Password: "token",
}
jiraClient, err := jira.NewClient(tp.Client(), base)
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
- andygrunwald/jitic - The Jira Ticket Checker
Development
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.
Unit testing
To run the local unit tests, execute
$ make test
To run the local unit tests and view the unit test code coverage in your local web browser, execute
$ make test-coverage-html
Contribution
We â¤ï¸ PR's
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 of 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.
Supported Go versions
We follow the Go Release Policy:
Each major Go release is supported until there are two newer major releases. For example, Go 1.5 was supported until the Go 1.7 release, and Go 1.6 was supported until the Go 1.8 release. We fix critical problems, including critical security problems, in supported releases as needed by issuing minor revisions (for example, Go 1.6.1, Go 1.6.2, and so on).
Supported Jira versions
Jira Server (On-Premise solution)
We follow the Atlassian Support End of Life Policy:
Atlassian supports feature versions for two years after the first major iteration of that version was released (for example, we support Jira Core 7.2.x for 2 years after Jira 7.2.0 was released).
Jira Cloud
We support Jira Cloud API in version 3. Even if this API version is currently in beta (by Atlassian):
Version 2 and version 3 of the API offer the same collection of operations. However, version 3 provides support for the Atlassian Document Format (ADF) in a subset of the API.
Official Jira API documentation
- Jira Server (On-Premise solution)
- Jira Cloud API in version 2
- Jira Cloud API in version 3
Sandbox environment for testing
Jira offers sandbox test environments at http://go.atlassian.com/cloud-dev.
You can read more about them at https://blog.developer.atlassian.com/cloud-ecosystem-dev-env/.
Releasing
Install standard-version
npm i -g standard-version
standard-version
git push --tags
Manually copy/paste text from changelog (for this new version) into the release on Github.com. E.g.
https://github.com/andygrunwald/go-jira/releases/edit/v1.11.0
License
This project is released under the terms of the MIT license.
Top Related Projects
simple jira command line client in Go
Go library for accessing the GitHub v3 API
GitLab Go SDK
Go Twitter REST and Streaming API v1.1
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot