Skip to content

Commit

Permalink
change github report foramt, squash some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-V committed Jan 23, 2021
1 parent d57a0e3 commit 21c9bb3
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 75 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,34 @@ Some example usages:
1. **JSON** (report.json)<br>
The JSON report can be used for other computational tasks as required (E.g emailing dead urls to yourself)
```json
[
{
"message": "Get http://127.0.0.1:8000/: dial tcp 127.0.0.1:8000: connect: connection refused",
"url": "http://127.0.0.1:8000/"
{
"http://127.0.0.1:8000/": {
"code": "",
"message": "Get \"http://127.0.0.1:8000/\": dial tcp 127.0.0.1:8000: connect: connection refused",
"response_time": ""
},
{
"http://freecodecamp.org": {
"code": "200",
"message": "OK",
"response_time": "0.77s",
"url": "http://prnbs.github.io/projects/regular-expression-parser/"
"response_time": "5.44s"
},
{
"http://ogp.me/": {
"code": "200",
"message": "OK",
"response_time": "2.59s",
"url": "https://swtch.com/~rsc/regexp/regexp1.html"
"response_time": "3.60s"
},
"http://prnbs.github.io/projects/regular-expression-parser/": {
"code": "200",
"message": "OK",
"response_time": "0.25s"
},
"https://bhupeshv.me/30-Seconds-of-C++/": {
"code": "404",
"message": "Not Found",
"response_time": "3.84s"
},
...
]
}
```

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

3. **HTML** (report.html)<br>
The html report is the most superior formats of all & can be used to have a visual representaion of analyzed links.<br>
Expand Down
41 changes: 34 additions & 7 deletions areyouok.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
Expand All @@ -27,8 +28,11 @@ var (
totalTime string
totalFiles int
totalLinks int
aroVersion string = "dev"
aroDate string = "dev"
//Do not modify, its done at compile time using ldflags
aroVersion string = "dev" //aro Version
aroDate string = "dev" //aro Build Date
branch_name string
repo_url string
)

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

func getGitDetails(userDir string) {
// get default branch name
cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "origin/HEAD")
cmd.Dir = userDir
branch, err := cmd.CombinedOutput()
if err == nil {
branch_name = strings.Trim(strings.Split(string(branch[:]), "/")[1], "\r\n")
}
// get repo url
config := exec.Command("git", "config", "--get", "remote.origin.url")
config.Dir = userDir
repo, err := config.CombinedOutput()
if err == nil {
repo_url = string(repo[:])
repo_url = repo_url[0 : len(repo_url)-5]
}
}

func getFiles(userPath string, filetype string, ignore []string) []string {
var validFiles []string

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

func getLinks(files []string) ([]map[string]string, map[string][]string) {
func getLinks(files []string, userDir string) ([]map[string]string, map[string][]string) {
hyperlinks := make(map[string][]string)
var allLinks []string
var allHyperlinks []map[string]string
Expand Down Expand Up @@ -131,7 +153,7 @@ func generateReport(validfiles map[string][]string, linkfr map[string]map[string
if err != nil {
fmt.Println(err)
}
f, _ := os.Create("report.html")
f, _ := os.Create(fmt.Sprintf("report.%s", reportType))
templateData := struct {
ValidFiles map[string][]string
ReLinks map[string]map[string]string
Expand All @@ -140,6 +162,8 @@ func generateReport(validfiles map[string][]string, linkfr map[string]map[string
TotalLinks string
TotalFiles string
TotalTime string
BranchName string
RepoURL string
}{
ValidFiles: validfiles,
ReLinks: linkfr,
Expand All @@ -148,6 +172,8 @@ func generateReport(validfiles map[string][]string, linkfr map[string]map[string
TotalLinks: strconv.Itoa(totalLinks),
TotalFiles: strconv.Itoa(totalFiles),
TotalTime: totalTime,
BranchName: branch_name,
RepoURL: repo_url,
}
t.Execute(f, templateData)
} else if reportType == "json" {
Expand Down Expand Up @@ -220,7 +246,7 @@ func main() {
}
flag.Parse()
if *Version {
fmt.Printf("AreYouOk %s on %s", aroVersion, aroDate)
fmt.Printf("AreYouOk %s built on %s", aroVersion, aroDate)
os.Exit(0)
}
if ignoreDirs != "" {
Expand All @@ -236,8 +262,9 @@ func main() {
fmt.Printf("%s in not a supported report format\n", reportType)
os.Exit(1)
}
var validFiles = getFiles(userDir, typeOfFile, dirs)
links, valid := getLinks(validFiles)
getGitDetails(userDir)
validFiles := getFiles(userDir, typeOfFile, dirs)
links, valid := getLinks(validFiles, userDir)
data := driver(links)
linkfr := make(map[string]map[string]string)
for _, v := range data {
Expand Down
108 changes: 52 additions & 56 deletions static/report_github.html
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
<h1>AreYouOk URL Health Report ⛑️ </h1>
<p>
{{.TotalLinks}} URLs were analyzed across {{.TotalFiles}} files in {{.TotalTime}}
</p>
<h3>
{{.TotalLinks}} URLs were analyzed across {{.TotalFiles}} files in {{.TotalTime}}
</h3>

<details open><summary>Not OK URLs</summary>
<table>
<tr>
<th width="70%">URL</th>
<th>Message</th>
</tr>
{{- range $url, $v := $.ReLinks}}
{{- if ne (index $v "message") "OK"}}
<tr>
<td><a href="{{print $url}}">{{print $url -}}</a></td>
<td align="center">{{print (index $v "message") -}}</td>
</tr>
<ol>
{{- range $k, $v := $.ValidFiles}}
{{- range $url := $v}}
{{- if ne (index (index $.ReLinks $url) "message") "OK"}}
<li>
<p class="filepath"><b><a href="{{$.RepoURL}}/blob/{{$.BranchName}}/{{$k}}">{{$k}}</a></b></p>
<table style="width:100%;margin-left: 0px;">
<tr>
<th width="70%">URL</th>
<th>Status</th>
<th>Message</th>
<th>Response Time</th>
</tr>
<tr class="c{{index (index $.ReLinks $url) "code" -}}">
<td><a href="{{$url}}">{{$url}}</a></td>
<td align="center">{{index (index $.ReLinks $url) "code"}}</td>
<td align="center">{{index (index $.ReLinks $url) "message"}}</td>
<td align="center">{{index (index $.ReLinks $url) "response_time"}}</td>
</tr>
</table>
</li>
{{- end}}
{{- end}}
</table>
{{- end}}
</ol>
</details>
<details open><summary>All URLs</summary>
<table>
<tr>
<th width="70%">URL</th>
<th>Status</th>
<th>Message</th>
<th>Response Time</th>
</tr>
{{- range $url, $v := $.ReLinks}}
<tr>
<td><a href="{{print $url}}">{{print $url -}}</a></td>
<td align="center">{{print (index $v "code") -}}</td>
<td align="center">{{print (index $v "message") -}}</td>
<td align="center">{{print (index $v "response_time") -}}</td>
</tr>

<details><summary>Detailed Report</summary>
<ol>
{{- range $k, $v := $.ValidFiles}}
<li>
<p class="filepath"><b><a href="{{$.RepoURL}}/blob/{{$.BranchName}}/{{$k}}">{{$k}}</a></b></p>
<table style="width:100%;margin-left: 0px;">
<tr>
<th width="70%">URL</th>
<th>Status</th>
<th>Message</th>
<th>Response Time</th>
</tr>
{{- range $url := $v}}
<tr class="c{{index (index $.ReLinks $url) "code" -}}">
<td><a href="{{$url}}">{{$url}}</a></td>
<td align="center">{{index (index $.ReLinks $url) "code"}}</td>
<td align="center">{{index (index $.ReLinks $url) "message"}}</td>
<td align="center">{{index (index $.ReLinks $url) "response_time"}}</td>
</tr>
{{- end}}
</table>
</li>
{{- end}}
</table>
</ol>
</details>
<div class="detailed-health-report">
<details open><summary>Detailed Report</summary>
<ol>
{{- range $k, $v := $.ValidFiles}}
<li>
<p class="filepath"><b><a href="{{$k}}">{{$k}}</a></b></p>
<table style="width:100%;margin-left: 0px;">
<tr>
<th width="70%">URL</th>
<th>Status</th>
<th>Message</th>
</tr>
{{- range $url := $v}}
<tr class="c{{index (index $.ReLinks $url) "code" -}}">
<td><a href="">{{$url}}</a></td>
<td align="center">{{index (index $.ReLinks $url) "code"}}</td>
<td align="center">{{index (index $.ReLinks $url) "message"}}</td>
</tr>
{{- end}}
</table>
</li>
{{- end}}
</ol>
</details>
</div>

<i><p>Report Generated at {{.Time}} on {{.Date}}</p></i>
<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>
2 changes: 1 addition & 1 deletion static/report_html.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h1>AreYouOk URL Health Report ⛑️ </h1>
<ol>
{{- range $k, $v := $.ValidFiles}}
<li>
<p class="filepath"><b><a href="{{$k}}">{{$k}}</a></b></p>
<p class="filepath"><b>{{$k}}</b></p>
<table style="width:100%;margin-left: 0px;">
<tr>
<th width="70%">URL</th>
Expand Down

0 comments on commit 21c9bb3

Please sign in to comment.