Created
October 1, 2014 21:52
-
-
Save codemac/1c4d8b98af82c83b8bc4 to your computer and use it in GitHub Desktop.
Github Issues & Pull Requests make me hate things
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 ( | |
"encoding/json" | |
"fmt" | |
"net/http" | |
) | |
type GSIUser struct { | |
Login string `json:"login"` | |
Id int `json:"id"` | |
Avatar_url string `json:"avatar_url"` | |
Gravatar_id string `json:"gravatar_id"` | |
Url string `json:"url"` | |
Html_url string `json:"html_url"` | |
Followers_url string `json:"followers_url"` | |
Following_url string `json:"following_url"` | |
Gists_url string `json:"gists_url"` | |
Starred_url string `json:"starred_url"` | |
Subscriptions_url string `json:"subscriptions_url"` | |
Organizations_url string `json:"organizations_url"` | |
Repos_url string `json:"repos_url"` | |
Events_url string `json:"events_url"` | |
Received_events_url string `json:"received_events_url"` | |
Type string `json:"type"` | |
SiteAdmin bool `json:"site_admin"` | |
} | |
type GSIResults struct { | |
TotalCount int `json:"total_count"` | |
IncompleteResults bool `json:"incomplete_results"` | |
Items []struct { | |
Url string `json:"url"` | |
LabelsUrl string `json:"labels_url"` | |
CommentsUrl string `json:"comments_url"` | |
EventsUrl string `json:"events_url"` | |
HtmlUrl string `json:"html_url"` | |
Id int `json:"id"` | |
Number int `json:"number"` | |
Title string `json:"title"` | |
User GSIUser `json:"user"` | |
Labels []struct { | |
Url string `json:"url"` | |
Name string `json:"name"` | |
Color string `json:"color"` | |
} `json:"labels"` | |
State string `json:"state"` | |
Assignee GSIUser `json:"assignee"` | |
Milestone string `json:"-"` | |
Comments int `json:"comments"` | |
CreatedAt string `json:"created_at"` | |
UpdatedAt string `json:"updated_at"` | |
ClosedAt string `json:"closed_at"` | |
PullRequest struct { | |
HtmlUrl string `json:"html_url"` | |
DiffUrl string `json:"diff_url"` | |
PatchUrl string `json:"patch_url"` | |
} `json:"pull_request"` | |
Body string `json:"body"` | |
Score float64 `json:"score"` | |
} `json:"items"` | |
} | |
func getResults() *GSIResults { | |
query := "?q=assignee:codemac+state:open" | |
api_base := "https://api.github.com/search/issues" | |
hr, err := http.NewRequest("GET", api_base+query, nil) // set up url | |
if err != nil { | |
fmt.Printf("error: %s\n", err) | |
panic(err) | |
} | |
hr.Header.Add("Accept", "application/vnd.github.v3+json") // get json | |
hr.SetBasicAuth("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "x-oauth-basic") // githubmagic | |
resp, err := http.DefaultClient.Do(hr) | |
if err != nil { | |
fmt.Printf("error: %s\n", err) | |
panic(err) | |
} | |
defer resp.Body.Close() | |
if resp.StatusCode != http.StatusOK { | |
fmt.Printf("StatusCode = %d\n", resp.StatusCode) | |
panic("No 200 ok given!") | |
} | |
var gr GSIResults | |
err = json.NewDecoder(resp.Body).Decode(&gr) | |
if err != nil { | |
fmt.Printf("error: %s\n", err) | |
panic(err) | |
} | |
return &gr | |
} | |
func main() { | |
gsir := getResults() | |
if gsir == nil { | |
panic("No gsi result") | |
} | |
fmt.Printf("Pull Requests Opened and Assigned to Codemac:\n") | |
fmt.Printf("_____________________________________________\n") | |
for _, iv := range gsir.Items { | |
if len(iv.PullRequest.HtmlUrl) != 0 { | |
fmt.Printf("%s\n", iv.PullRequest.HtmlUrl) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment