Skip to content

Instantly share code, notes, and snippets.

@imantung
Created July 30, 2022 13:46
Show Gist options
  • Save imantung/dad932e1623b8c3b3d5fdd70baf3fef1 to your computer and use it in GitHub Desktop.
Save imantung/dad932e1623b8c3b3d5fdd70baf3fef1 to your computer and use it in GitHub Desktop.
Golang fetch from jira
package main
import (
"fmt"
"log"
gojira "github.com/andygrunwald/go-jira"
)
// Example to fetch data from Jira
var (
// Username is your registered email
username = "your@email.com"
// Create API token at https://id.atlassian.com/manage-profile/security/api-tokens
// Learn more: https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/
token = "TOKEN"
// Jira URL
url = "https://YOUR_ORG.atlassian.net"
)
func main() {
tp := gojira.BasicAuthTransport{
Username: username,
Password: token,
}
client, err := gojira.NewClient(tp.Client(), url)
fatalIfError(err, "Failed to create jira client")
projectList, _, err := client.Project.GetList()
fatalIfError(err, "Unable to get project list")
for _, project := range *projectList {
fmt.Printf("%s: %s\n", project.Key, project.Name)
}
}
func fatalIfError(err error, info string) {
if err != nil {
log.Fatalf("%s: %v", info, err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment