Skip to content

Commit 21c9bb3

Browse files
committed
change github report foramt, squash some bugs
1 parent d57a0e3 commit 21c9bb3

File tree

4 files changed

+108
-75
lines changed

4 files changed

+108
-75
lines changed

README.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,34 @@ Some example usages:
9090
1. **JSON** (report.json)<br>
9191
The JSON report can be used for other computational tasks as required (E.g emailing dead urls to yourself)
9292
```json
93-
[
94-
{
95-
"message": "Get http://127.0.0.1:8000/: dial tcp 127.0.0.1:8000: connect: connection refused",
96-
"url": "http://127.0.0.1:8000/"
93+
{
94+
"http://127.0.0.1:8000/": {
95+
"code": "",
96+
"message": "Get \"http://127.0.0.1:8000/\": dial tcp 127.0.0.1:8000: connect: connection refused",
97+
"response_time": ""
9798
},
98-
{
99+
"http://freecodecamp.org": {
99100
"code": "200",
100101
"message": "OK",
101-
"response_time": "0.77s",
102-
"url": "http://prnbs.github.io/projects/regular-expression-parser/"
102+
"response_time": "5.44s"
103103
},
104-
{
104+
"http://ogp.me/": {
105105
"code": "200",
106106
"message": "OK",
107-
"response_time": "2.59s",
108-
"url": "https://swtch.com/~rsc/regexp/regexp1.html"
107+
"response_time": "3.60s"
108+
},
109+
"http://prnbs.github.io/projects/regular-expression-parser/": {
110+
"code": "200",
111+
"message": "OK",
112+
"response_time": "0.25s"
113+
},
114+
"https://bhupeshv.me/30-Seconds-of-C++/": {
115+
"code": "404",
116+
"message": "Not Found",
117+
"response_time": "3.84s"
109118
},
110119
...
111-
]
120+
}
112121
```
113122

114123
2. **Text** (report.txt)<br>
@@ -128,6 +137,7 @@ Some example usages:
128137
https://github.com/codeclassroom/PlagCheck/blob/master/docs/docs.md
129138
https://bhupeshv.me/30-Seconds-of-C++/
130139
```
140+
Note that the total time would vary according to your internet speed & website latency.
131141

132142
3. **HTML** (report.html)<br>
133143
The html report is the most superior formats of all & can be used to have a visual representaion of analyzed links.<br>

areyouok.go

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"net/url"
1313
"os"
14+
"os/exec"
1415
"path/filepath"
1516
"regexp"
1617
"strconv"
@@ -27,8 +28,11 @@ var (
2728
totalTime string
2829
totalFiles int
2930
totalLinks int
30-
aroVersion string = "dev"
31-
aroDate string = "dev"
31+
//Do not modify, its done at compile time using ldflags
32+
aroVersion string = "dev" //aro Version
33+
aroDate string = "dev" //aro Build Date
34+
branch_name string
35+
repo_url string
3236
)
3337

3438
func checkLink(link string, wg *sync.WaitGroup, ch chan map[string]string) {
@@ -65,6 +69,24 @@ func in(a string, list []string) bool {
6569
return false
6670
}
6771

72+
func getGitDetails(userDir string) {
73+
// get default branch name
74+
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "origin/HEAD")
75+
cmd.Dir = userDir
76+
branch, err := cmd.CombinedOutput()
77+
if err == nil {
78+
branch_name = strings.Trim(strings.Split(string(branch[:]), "/")[1], "\r\n")
79+
}
80+
// get repo url
81+
config := exec.Command("git", "config", "--get", "remote.origin.url")
82+
config.Dir = userDir
83+
repo, err := config.CombinedOutput()
84+
if err == nil {
85+
repo_url = string(repo[:])
86+
repo_url = repo_url[0 : len(repo_url)-5]
87+
}
88+
}
89+
6890
func getFiles(userPath string, filetype string, ignore []string) []string {
6991
var validFiles []string
7092

@@ -89,7 +111,7 @@ func getFiles(userPath string, filetype string, ignore []string) []string {
89111
return validFiles
90112
}
91113

92-
func getLinks(files []string) ([]map[string]string, map[string][]string) {
114+
func getLinks(files []string, userDir string) ([]map[string]string, map[string][]string) {
93115
hyperlinks := make(map[string][]string)
94116
var allLinks []string
95117
var allHyperlinks []map[string]string
@@ -131,7 +153,7 @@ func generateReport(validfiles map[string][]string, linkfr map[string]map[string
131153
if err != nil {
132154
fmt.Println(err)
133155
}
134-
f, _ := os.Create("report.html")
156+
f, _ := os.Create(fmt.Sprintf("report.%s", reportType))
135157
templateData := struct {
136158
ValidFiles map[string][]string
137159
ReLinks map[string]map[string]string
@@ -140,6 +162,8 @@ func generateReport(validfiles map[string][]string, linkfr map[string]map[string
140162
TotalLinks string
141163
TotalFiles string
142164
TotalTime string
165+
BranchName string
166+
RepoURL string
143167
}{
144168
ValidFiles: validfiles,
145169
ReLinks: linkfr,
@@ -148,6 +172,8 @@ func generateReport(validfiles map[string][]string, linkfr map[string]map[string
148172
TotalLinks: strconv.Itoa(totalLinks),
149173
TotalFiles: strconv.Itoa(totalFiles),
150174
TotalTime: totalTime,
175+
BranchName: branch_name,
176+
RepoURL: repo_url,
151177
}
152178
t.Execute(f, templateData)
153179
} else if reportType == "json" {
@@ -220,7 +246,7 @@ func main() {
220246
}
221247
flag.Parse()
222248
if *Version {
223-
fmt.Printf("AreYouOk %s on %s", aroVersion, aroDate)
249+
fmt.Printf("AreYouOk %s built on %s", aroVersion, aroDate)
224250
os.Exit(0)
225251
}
226252
if ignoreDirs != "" {
@@ -236,8 +262,9 @@ func main() {
236262
fmt.Printf("%s in not a supported report format\n", reportType)
237263
os.Exit(1)
238264
}
239-
var validFiles = getFiles(userDir, typeOfFile, dirs)
240-
links, valid := getLinks(validFiles)
265+
getGitDetails(userDir)
266+
validFiles := getFiles(userDir, typeOfFile, dirs)
267+
links, valid := getLinks(validFiles, userDir)
241268
data := driver(links)
242269
linkfr := make(map[string]map[string]string)
243270
for _, v := range data {

static/report_github.html

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,61 @@
11
<h1>AreYouOk URL Health Report ⛑️ </h1>
2-
<p>
3-
{{.TotalLinks}} URLs were analyzed across {{.TotalFiles}} files in {{.TotalTime}}
4-
</p>
2+
<h3>
3+
{{.TotalLinks}} URLs were analyzed across {{.TotalFiles}} files in {{.TotalTime}}
4+
</h3>
5+
56
<details open><summary>Not OK URLs</summary>
6-
<table>
7-
<tr>
8-
<th width="70%">URL</th>
9-
<th>Message</th>
10-
</tr>
11-
{{- range $url, $v := $.ReLinks}}
12-
{{- if ne (index $v "message") "OK"}}
13-
<tr>
14-
<td><a href="{{print $url}}">{{print $url -}}</a></td>
15-
<td align="center">{{print (index $v "message") -}}</td>
16-
</tr>
7+
<ol>
8+
{{- range $k, $v := $.ValidFiles}}
9+
{{- range $url := $v}}
10+
{{- if ne (index (index $.ReLinks $url) "message") "OK"}}
11+
<li>
12+
<p class="filepath"><b><a href="{{$.RepoURL}}/blob/{{$.BranchName}}/{{$k}}">{{$k}}</a></b></p>
13+
<table style="width:100%;margin-left: 0px;">
14+
<tr>
15+
<th width="70%">URL</th>
16+
<th>Status</th>
17+
<th>Message</th>
18+
<th>Response Time</th>
19+
</tr>
20+
<tr class="c{{index (index $.ReLinks $url) "code" -}}">
21+
<td><a href="{{$url}}">{{$url}}</a></td>
22+
<td align="center">{{index (index $.ReLinks $url) "code"}}</td>
23+
<td align="center">{{index (index $.ReLinks $url) "message"}}</td>
24+
<td align="center">{{index (index $.ReLinks $url) "response_time"}}</td>
25+
</tr>
26+
</table>
27+
</li>
1728
{{- end}}
1829
{{- end}}
19-
</table>
30+
{{- end}}
31+
</ol>
2032
</details>
21-
<details open><summary>All URLs</summary>
22-
<table>
23-
<tr>
24-
<th width="70%">URL</th>
25-
<th>Status</th>
26-
<th>Message</th>
27-
<th>Response Time</th>
28-
</tr>
29-
{{- range $url, $v := $.ReLinks}}
30-
<tr>
31-
<td><a href="{{print $url}}">{{print $url -}}</a></td>
32-
<td align="center">{{print (index $v "code") -}}</td>
33-
<td align="center">{{print (index $v "message") -}}</td>
34-
<td align="center">{{print (index $v "response_time") -}}</td>
35-
</tr>
33+
34+
<details><summary>Detailed Report</summary>
35+
<ol>
36+
{{- range $k, $v := $.ValidFiles}}
37+
<li>
38+
<p class="filepath"><b><a href="{{$.RepoURL}}/blob/{{$.BranchName}}/{{$k}}">{{$k}}</a></b></p>
39+
<table style="width:100%;margin-left: 0px;">
40+
<tr>
41+
<th width="70%">URL</th>
42+
<th>Status</th>
43+
<th>Message</th>
44+
<th>Response Time</th>
45+
</tr>
46+
{{- range $url := $v}}
47+
<tr class="c{{index (index $.ReLinks $url) "code" -}}">
48+
<td><a href="{{$url}}">{{$url}}</a></td>
49+
<td align="center">{{index (index $.ReLinks $url) "code"}}</td>
50+
<td align="center">{{index (index $.ReLinks $url) "message"}}</td>
51+
<td align="center">{{index (index $.ReLinks $url) "response_time"}}</td>
52+
</tr>
53+
{{- end}}
54+
</table>
55+
</li>
3656
{{- end}}
37-
</table>
57+
</ol>
3858
</details>
39-
<div class="detailed-health-report">
40-
<details open><summary>Detailed Report</summary>
41-
<ol>
42-
{{- range $k, $v := $.ValidFiles}}
43-
<li>
44-
<p class="filepath"><b><a href="{{$k}}">{{$k}}</a></b></p>
45-
<table style="width:100%;margin-left: 0px;">
46-
<tr>
47-
<th width="70%">URL</th>
48-
<th>Status</th>
49-
<th>Message</th>
50-
</tr>
51-
{{- range $url := $v}}
52-
<tr class="c{{index (index $.ReLinks $url) "code" -}}">
53-
<td><a href="">{{$url}}</a></td>
54-
<td align="center">{{index (index $.ReLinks $url) "code"}}</td>
55-
<td align="center">{{index (index $.ReLinks $url) "message"}}</td>
56-
</tr>
57-
{{- end}}
58-
</table>
59-
</li>
60-
{{- end}}
61-
</ol>
62-
</details>
63-
</div>
59+
6460
<i><p>Report Generated at {{.Time}} on {{.Date}}</p></i>
6561
<i><p><a href="https://github.com/Bhupesh-V/areyouok/issues/new/choose"><b>🐞 Report Bug </b></a> | <a href="https://bhupesh-v.github.io/about/#-support"><b>💰 Support</b></a> | <a href="https://github.com/Bhupesh-V/areyouok"><b>⭐ Give us a Star</b></a></p></i>

static/report_html.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ <h1>AreYouOk URL Health Report ⛑️ </h1>
8585
<ol>
8686
{{- range $k, $v := $.ValidFiles}}
8787
<li>
88-
<p class="filepath"><b><a href="{{$k}}">{{$k}}</a></b></p>
88+
<p class="filepath"><b>{{$k}}</b></p>
8989
<table style="width:100%;margin-left: 0px;">
9090
<tr>
9191
<th width="70%">URL</th>

0 commit comments

Comments
 (0)