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

have fixed so that i get commits and repository name from the link, and i have...

have fixed so that i get commits and repository name from the link, and i have sorted the output so that the repository with most commits gets printet out on top
parent e5bed4f8
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"sort"
"strconv" "strconv"
) )
...@@ -46,38 +47,40 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) { ...@@ -46,38 +47,40 @@ func HandlerCommits(w http.ResponseWriter, r *http.Request) {
APIURL := "https://git.gvk.idi.ntnu.no/api/v4/projects" APIURL := "https://git.gvk.idi.ntnu.no/api/v4/projects"
Client := http.DefaultClient Client := http.DefaultClient
//limit := QueryGet("limit", "5", r)
// auth := QueryGet("auth", "false", r) // auth := QueryGet("auth", "false", r)
resp := DoRequest(Client, w, APIURL) resp := DoRequest(Client, w, APIURL)
json.NewDecoder(resp.Body).Decode(&I) json.NewDecoder(resp.Body).Decode(&I)
var T Temp resp = DoRequest(Client, w, APIURL)
json.NewDecoder(resp.Body).Decode(&C.Repos)
erer := len(I)
fmt.Println("heree:", erer)
for i := range I { for i := range I {
URL := APIURL + "/" + strconv.Itoa(I[i].ID) + "/repository/commits" URL := APIURL + "/" + strconv.Itoa(I[i].ID) + "/repository/commits"
resp = DoRequest(Client, w, URL) resp = DoRequest(Client, w, URL)
json.NewDecoder(resp.Body).Decode(&C.Repose) var Temp []Temp
Temp := len(C.Repose) json.NewDecoder(resp.Body).Decode(&Temp)
T.TempInt = Temp
fmt.Println(Temp)
fmt.Println(T.TempInt)
} C.Repos[i].Commits = len(Temp)
C.Repos[i].Repository = I[i].Name
for i := range C.Repose {
C.Repose[i].Repository = I[i].Name
C.Repose[i].Commits = T.TempInt
} }
sort.Slice(C.Repos, func(i, j int) bool { return C.Repos[i].Commits > C.Repos[j].Commits })
//limit := QueryGet("limit", "5", r)
http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good http.Header.Add(w.Header(), "Content-Type", "application/json") // makes the print look good
//json.NewEncoder(w).Encode(I)
json.NewEncoder(w).Encode(C) json.NewEncoder(w).Encode(C)
} }
......
...@@ -4,7 +4,7 @@ package assignment2 ...@@ -4,7 +4,7 @@ package assignment2
type IDS struct { type IDS struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name_with_namespace"` Name string `json:"path_with_namespace"`
} }
type Temp struct { type Temp struct {
...@@ -17,7 +17,7 @@ type RepoAndCommit struct { ...@@ -17,7 +17,7 @@ type RepoAndCommit struct {
} }
type Commits struct { type Commits struct {
Repose []RepoAndCommit Repos []RepoAndCommit
Auth bool `json:"auth"` Auth bool `json:"auth"`
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment