Created
November 28, 2023 19:11
-
-
Save niski84/01577527c4e7b693298190952e7d1041 to your computer and use it in GitHub Desktop.
jira fetch issue
This file contains 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 ( | |
"bytes" | |
"encoding/json" | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
) | |
// Jira API token | |
const token = " token" | |
// jiraIssue fetches the Jira issue | |
func jiraIssue() { | |
url := "https://jiraServer.net/rest/api/2/issue/CCM-13494" | |
req, err := http.NewRequest("GET", url, nil) | |
if err != nil { | |
fmt.Println("error creating request:", err) | |
return | |
} | |
req.Header.Add("Authorization", "Bearer "+token) | |
req.Header.Add("Content-Type", "application/json") | |
client := &http.Client{} | |
resp, err := client.Do(req) | |
if err != nil { | |
fmt.Println("error sending request:", err) | |
return | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
fmt.Println("error reading response:", err) | |
return | |
} | |
// print the full json response | |
fmt.Println("Full JSON Response:\n", string(body)) | |
var result map[string]interface{} | |
if err := json.Unmarshal(body, &result); err != nil { | |
fmt.Println("error unmarshaling json:", err) | |
return | |
} | |
// print only the custom fields | |
if fields, ok := result["fields"].(map[string]interface{}); ok { | |
fmt.Println("Custom Fields:") | |
for key, value := range fields { | |
if bytes.HasPrefix([]byte(key), []byte("customfield_")) { | |
fmt.Printf("%s: %v\n", key, value) | |
} | |
} | |
} | |
customFieldKey := "customfield_XXXX" // replace with actual key | |
if fields, ok := result["fields"].(map[string]interface{}); ok { | |
if apvCloudOps, ok := fields[customFieldKey]; ok { | |
fmt.Printf("Apv CloudOps: %v\n", apvCloudOps) | |
} else { | |
fmt.Println("Apv CloudOps field not found") | |
} | |
} | |
} | |
func main() { | |
jiraIssue() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment