Created
December 2, 2020 19:09
-
-
Save bianpengyuan/3f229721a733f560fd28345a7866b4ab to your computer and use it in GitHub Desktop.
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 ( | |
"encoding/csv" | |
"encoding/json" | |
"flag" | |
"io/ioutil" | |
"log" | |
"os" | |
"sort" | |
"strings" | |
) | |
type issueRank [][]string | |
func (ir issueRank) Swap(i, j int) { | |
ir[i], ir[j] = ir[j], ir[i] | |
} | |
func (ir issueRank) Len() int { | |
return len(ir) | |
} | |
func (ir issueRank) Less(i, j int) bool { | |
order := map[string]int{"Release Blocker": 0, "P0": 1, "P1": 2, "needs triage": 3} | |
ip := order[ir[i][0]] | |
jp := order[ir[j][0]] | |
if ip < jp { | |
return true | |
} else if jp < ip { | |
return false | |
} | |
return ir[i][1] < ir[j][1] | |
} | |
// To use this program, run `go run main.go -filepath=raw-issue.json > tracking.csv` | |
func main() { | |
issueJSONPath := flag.String("filepath", "", "") | |
flag.Parse() | |
content, err := ioutil.ReadFile(*issueJSONPath) | |
if err != nil { | |
log.Fatal(err) | |
} | |
var result map[string]interface{} | |
json.Unmarshal(content, &result) | |
issues := result["data"].(map[string]interface{})["repository"].(map[string]interface{})["milestone"].(map[string]interface{})["issues"].(map[string]interface{})["edges"].([]interface{}) | |
w := csv.NewWriter(os.Stdout) | |
w.Write([]string{"Priority", "Issue", "Subject", "ETA", "Resolution", "assignee"}) | |
records := make([][]string, 0) | |
for _, issue := range issues { | |
issueEntry := issue.(map[string]interface{})["node"].(map[string]interface{}) | |
record := make([]string, 0) | |
// Get priority | |
projectCardNodes := issueEntry["projectCards"].(map[string]interface{})["nodes"].([]interface{}) | |
if len(projectCardNodes) > 0 { | |
priority := projectCardNodes[0].(map[string]interface{})["column"].(map[string]interface{})["name"].(string) | |
if priority != "P0" && priority != "Release Blocker" { | |
continue | |
} | |
record = append(record, priority) | |
} else { | |
record = append(record, "needs triage") | |
} | |
// Get issue link | |
record = append(record, issueEntry["url"].(string)) | |
// Get subject | |
record = append(record, issueEntry["title"].(string)) | |
// empty eta | |
record = append(record, "") | |
// empty resolution | |
record = append(record, "") | |
// assignees | |
assignees := issueEntry["assignees"].(map[string]interface{})["edges"].([]interface{}) | |
assigneeSlice := make([]string, 0) | |
for _, assignee := range assignees { | |
assigneeSlice = append(assigneeSlice, assignee.(map[string]interface{})["node"].(map[string]interface{})["login"].(string)) | |
} | |
record = append(record, strings.Join(assigneeSlice, ",")) | |
records = append(records, record) | |
} | |
sort.Sort(issueRank(records)) | |
for _, r := range records { | |
w.Write(r) | |
} | |
w.Flush() | |
if err := w.Error(); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment