Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Assignment2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kenneth Tran
Assignment2
Commits
995612ab
Commit
995612ab
authored
Oct 29, 2019
by
Kenneth Tran
Browse files
Options
Downloads
Patches
Plain Diff
Update strucs and improved handlerCommits etc
parent
2a6af9fc
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
main
+0
-0
0 additions, 0 deletions
main
main.go
+4
-4
4 additions, 4 deletions
main.go
packs/commits.go
+27
-47
27 additions, 47 deletions
packs/commits.go
packs/languages.go
+1
-0
1 addition, 0 deletions
packs/languages.go
packs/status.go
+2
-0
2 additions, 0 deletions
packs/status.go
with
34 additions
and
51 deletions
main
0 → 100755
+
0
−
0
View file @
995612ab
File added
This diff is collapsed.
Click to expand it.
main.go
+
4
−
4
View file @
995612ab
package
main
import
(
"net/http"
A
"oblig2/packs"
"log"
"net/http"
"os"
A
"oblig2/packs"
)
func
main
(){
port
:=
os
.
Getenv
(
"PORT"
)
port
=
"8080"
...
...
@@ -15,7 +17,5 @@ func main(){
}
A
.
GetCommits
()
log
.
Fatal
(
http
.
ListenAndServe
(
":"
+
port
,
nil
))
// B.GetIssues()
// C.GetLanguages()
}
This diff is collapsed.
Click to expand it.
packs/commits.go
+
27
−
47
View file @
995612ab
...
...
@@ -9,76 +9,56 @@ import (
"strconv"
)
const
URL
=
"https://gitlab.example.com/api/v4/projects"
const
APIROOT
=
"https://git.gvk.idi.ntnu.no/api/v4/projects/"
const
Version
=
"v1"
type
Repo1
struct
{
//struct repo with most commits
// struct with repodata
type
Repo1
struct
{
Id
int
`json: "id"`
MostCommits
string
`json:"path_with_namespace"`
Counter
Counter
// Counter1 //convert to Jsonformat
}
Name
string
`json: "name_with_namespace"`
Path
string
`json: "path_with_namespace"`
Counter
int
`json:"commits"`
type
Repo2
struct
{
// struct repo with second most commits
SecondCommits
string
`json:"path_with_namespace"`
// Counter2 int //convert to Jsonformat
}
// struct with string of id
type
Counter
struct
{
Counter
int
`json:"counter"`
}
type
MergeRep
struct
{
Repo1
Repo1
Repo2
Repo2
Id
string
`json:"id"`
}
func
GetCommits
(){
http
.
HandleFunc
(
"/repocheck/v1/commits"
,
handlerCommits
)
}
func
countMost
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
pointer
*
[]
Repo1
,
pointer2
*
[]
Counter
){
for
j
:=
0
;
j
<=
len
(
*
pointer
);
j
++
{
spesificPro
:=
strconv
.
Itoa
((
*
pointer
)[
j
]
.
Id
)
url
:=
URL
+
spesificPro
+
"/repository/commits"
response
,
err
:=
http
.
Get
(
url
)
if
err
!=
nil
{
//error handler
fmt
.
Println
(
"Error: we have a problem"
,
err
)
http
.
HandleFunc
(
"/repocheck/v1/commits/"
,
handlerCommits
)
}
// create an array of id`s
var
buffer
[]
Counter
err
=
json
.
NewDecoder
(
response
.
Body
)
.
Decode
(
&
buffer
)
counter
:=
len
(
buffer
)
(
*
pointer2
)[
j
]
.
Counter
=
counter
func
countCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
,
Repos
*
[]
Repo1
)
{
for
i
:=
0
;
i
<
len
(
*
Repos
);
i
++
{
proId
:=
strconv
.
Itoa
((
*
Repos
)[
i
]
.
Id
)
// convert to string
url
:=
APIROOT
+
proId
+
"/repository/commits/"
response
,
_
:=
http
.
Get
(
url
)
var
content
[]
Counter
json
.
NewDecoder
(
response
.
Body
)
.
Decode
(
&
content
)
count
:=
len
(
content
)
(
*
Repos
)[
i
]
.
Counter
=
count
//update variable Counter in Repo1 struct
}
}
func
handlerCommits
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
response
,
err
:=
http
.
Get
(
URL
)
if
err
!=
nil
{
//error handler
response
,
err
:=
http
.
Get
(
APIROOT
)
// url = apiroot + "?per_page" + limit
if
err
!=
nil
{
fmt
.
Println
(
"Error: we have a problem"
,
err
)
return
}
var
content
Repo1
var
content2
Repo2
var
merged
MergeRep
countMost
(
w
,
r
,
&
content
,
&
Repo2
)
var
content
[]
Repo1
err
=
json
.
NewDecoder
(
response
.
Body
)
.
Decode
(
&
content
)
countCommits
(
w
,
r
,
&
content
)
merged
.
Repo1
=
content
merged
.
Repo2
=
content2
var
buffer
=
new
(
bytes
.
Buffer
)
encode
:=
json
.
NewEncoder
(
buffer
)
encode
.
Encode
(
merged
)
encode
.
Encode
(
content
)
w
.
Header
()
.
Set
(
"Content-type"
,
"application/json"
)
w
.
WriteHeader
(
http
.
StatusAccepted
)
io
.
Copy
(
w
,
buffer
)
}
This diff is collapsed.
Click to expand it.
packs/languages.go
+
1
−
0
View file @
995612ab
package
packs
This diff is collapsed.
Click to expand it.
packs/status.go
+
2
−
0
View file @
995612ab
package
packs
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment