Skip to content
Snippets Groups Projects
Commit 04083b4f authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

changed how i read inn commits count and startet on chang the way i get...

changed how i read inn commits count and startet on chang the way i get repositoris so that i het all an not just 20 first
parent 5a69b118
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,6 @@ package assignment2 ...@@ -2,7 +2,6 @@ package assignment2
import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"net/http" "net/http"
"sort" "sort"
...@@ -19,15 +18,22 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) { ...@@ -19,15 +18,22 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
Client := http.DefaultClient Client := http.DefaultClient
APIURL := URL1 APIURL := URL1
URL3 := APIURL + "?per_page=100&page=" + strconv.Itoa(1)
auth := QueryGet("auth", "false", r) auth := QueryGet("auth", "false", r)
if auth != "false" { if auth != "false" {
APIURL = URL2 + auth APIURL = URL2 + auth
URL3 = URL2 + auth + "&per_page=100&page=" + strconv.Itoa(1)
C.Auth = true C.Auth = true
} }
fmt.Println(auth)
fmt.Println(APIURL)
resp := DoRequest(Client, w, APIURL) //fmt.Println(URL3)
// I = GetAll(w, APIURL, I)
resp := DoRequest(Client, w, URL3)
// resp = DoRequest(Client, w, URL3)
err := json.NewDecoder(resp.Body).Decode(&I) err := json.NewDecoder(resp.Body).Decode(&I)
if err != nil { if err != nil {
...@@ -35,7 +41,7 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) { ...@@ -35,7 +41,7 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
return return
} }
resp = DoRequest(Client, w, APIURL) resp = DoRequest(Client, w, URL3)
err = json.NewDecoder(resp.Body).Decode(&C.Repos) err = json.NewDecoder(resp.Body).Decode(&C.Repos)
if err != nil { if err != nil {
...@@ -43,23 +49,41 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) { ...@@ -43,23 +49,41 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
return return
} }
// resp := DoRequest(Client, w, APIURL)
// err := json.NewDecoder(resp.Body).Decode(&I)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
// resp = DoRequest(Client, w, APIURL)
// err = json.NewDecoder(resp.Body).Decode(&C.Repos)
// if err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
var TempCommit int
for i := range I { for i := range I {
URL := URL1 + "/" + strconv.Itoa(I[i].ID) + "/repository/commits" URL := URL1 + "/" + strconv.Itoa(I[i].ID) + "/repository/commits"
if auth != "false" { if auth != "false" {
URL = URL + "?private_token=" + auth URL = URL + "?private_token=" + auth + "&per_page=100&page=" + strconv.Itoa(1)
} }
// else {
// URL = URL + "?per_page=100&page=" + strconv.Itoa(1)
// }
resp = DoRequest(Client, w, URL) resp := DoRequest(Client, w, URL)
var Temp []Temp
err = json.NewDecoder(resp.Body).Decode(&Temp) TempCommit, err = strconv.Atoi(resp.Header.Get("X-Total"))
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest) log.Fatal(err)
return
} }
C.Repos[i].Commits = len(Temp) C.Repos[i].Commits = TempCommit
C.Repos[i].Repository = I[i].Name C.Repos[i].Repository = I[i].Name
......
...@@ -8,7 +8,7 @@ type IDS struct { ...@@ -8,7 +8,7 @@ type IDS struct {
} }
type Temp struct { type Temp struct {
TempInt int TempInt int `json:"x-Total"`
} }
type RepoAndCommit struct { type RepoAndCommit struct {
...@@ -21,7 +21,7 @@ type Commits struct { ...@@ -21,7 +21,7 @@ type Commits struct {
Auth bool `json:"auth"` Auth bool `json:"auth"`
} }
// *********** Lanlguage ************ // *********** Language ************
type IDLang struct { type IDLang struct {
ID int `json:"id"` ID int `json:"id"`
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment