Created
July 30, 2022 13:46
-
-
Save imantung/dad932e1623b8c3b3d5fdd70baf3fef1 to your computer and use it in GitHub Desktop.
Golang fetch from jira
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
gojira "github.com/andygrunwald/go-jira" | |
) | |
// Example to fetch data from Jira | |
var ( | |
// Username is your registered email | |
username = "[email protected]" | |
// 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