Skip to content

Instantly share code, notes, and snippets.

View percybolmer's full-sized avatar

ProgrammingPercy percybolmer

View GitHub Profile
func main() {
// Load the .env file
godotenv.Load(".env")
// Create a BasicAuth Transport object
tp := jira.BasicAuthTransport{
Username: os.Getenv("JIRA_USER"),
Password: os.Getenv("JIRA_TOKEN"),
}
// Create a new Jira Client
client, err := jira.NewClient(tp.Client(), os.Getenv("JIRA_URL"))
// getIssues will query Jira API using the provided JQL string
func getIssues(client *jira.Client, jql string) ([]jira.Issue, error) {
// lastIssue is the index of the last issue returned
lastIssue := 0
// Make a loop through amount of issues
var result []jira.Issue
for {
// Add a Search option which accepts maximum amount (1000)
opt := &jira.SearchOptions{
i := jira.Issue{
Fields: &jira.IssueFields{
Assignee: &jira.User{
Name: "myuser",
},
Reporter: &jira.User{
Name: "youruser",
},
Description: "Test Issue",
Type: jira.IssueType{
// getIssueTransition will grab the available transitions for a issue
func getIssueTransition(client *jira.Client, issue jira.Issue, status string) (jira.Transition, error) {
transitions, _, err := client.Issue.GetTransitions(issue.Key)
if err != nil {
return jira.Transition{}, err
}
for _, t := range transitions {
if t.Name == status {
return t, nil
}
func main() {
// Load the .env file
godotenv.Load(".env")
// Create a BasicAuth Transport object
tp := jira.BasicAuthTransport{
Username: os.Getenv("JIRA_USER"),
Password: os.Getenv("JIRA_TOKEN"),
}
// Create a new Jira Client
client, err := jira.NewClient(tp.Client(), os.Getenv("JIRA_URL"))
// transitionIssue will move a issue into the new transition
func transitionIssue(client *jira.Client, issue jira.Issue, transition jira.Transition) error {
_, err := client.Issue.DoTransition(issue.ID, transition.ID)
return err
}
2021/08/04 21:19:40 Hello
{"level":"debug", "time":"2021-08-04T21:19:40+02:00","message":"Hello"}
{"level":"info","service":"my-service","Some integer":10,"time":"2021-08-04T21:30:56+02:00","message":"Hello"}
{"level":"info","service":"my-service","Some integer":10,"time":"2021-08-04T21:37:09+02:00","message":"Hello"}
{"level":"info","service":"my-service","node":"localhost","count":1,"time":"2021-08-04T21:47:34+02:00","message":"Hello"}
{"level":"info","service":"my-service","node":"localhost","count":2,"time":"2021-08-04T21:47:34+02:00","message":"Hello"}