Skip to content

Commit 5eacd49

Browse files
authored
Merge pull request #79 from arduino/per1234/readme-check
Add checks for missing readme
2 parents db3526b + 510467c commit 5eacd49

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed

Diff for: check/checkconfigurations/checkconfigurations.go

+30
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,21 @@ var configurations = []Type{
956956
ErrorModes: []checkmode.Type{checkmode.Default},
957957
CheckFunction: checkfunctions.ProhibitedCharactersInLibraryFolderName,
958958
},
959+
{
960+
ProjectType: projecttype.Library,
961+
Category: "structure",
962+
Subcategory: "",
963+
ID: "",
964+
Brief: "no readme",
965+
Description: "",
966+
MessageTemplate: "No readme found. Please document your library. See: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-readmes",
967+
DisableModes: nil,
968+
EnableModes: []checkmode.Type{checkmode.Default},
969+
InfoModes: nil,
970+
WarningModes: []checkmode.Type{checkmode.Default},
971+
ErrorModes: []checkmode.Type{checkmode.Strict},
972+
CheckFunction: checkfunctions.MissingReadme,
973+
},
959974
{
960975
ProjectType: projecttype.Sketch,
961976
Category: "structure",
@@ -1121,4 +1136,19 @@ var configurations = []Type{
11211136
ErrorModes: []checkmode.Type{checkmode.Strict},
11221137
CheckFunction: checkfunctions.PdeSketchExtension,
11231138
},
1139+
{
1140+
ProjectType: projecttype.Sketch,
1141+
Category: "structure",
1142+
Subcategory: "",
1143+
ID: "",
1144+
Brief: "no readme",
1145+
Description: "",
1146+
MessageTemplate: "No readme found. Please document your sketch. See: https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-readmes",
1147+
DisableModes: nil,
1148+
EnableModes: []checkmode.Type{checkmode.Default},
1149+
InfoModes: nil,
1150+
WarningModes: []checkmode.Type{checkmode.Default},
1151+
ErrorModes: []checkmode.Type{checkmode.Strict},
1152+
CheckFunction: checkfunctions.MissingReadme,
1153+
},
11241154
}

Diff for: check/checkfunctions/checkfunctions.go

+33
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"regexp"
2121
"strings"
2222

23+
"github.com/arduino/arduino-check/check/checkdata"
2324
"github.com/arduino/arduino-check/check/checkresult"
2425
"github.com/arduino/go-paths-helper"
2526
)
@@ -64,3 +65,35 @@ func containsIncorrectPathBaseCase(pathList paths.PathList, correctBaseName stri
6465

6566
return nil, false
6667
}
68+
69+
// MissingReadme checks if the project has a readme that will be recognized by GitHub.
70+
func MissingReadme() (result checkresult.Type, output string) {
71+
// https://github.com/github/markup/blob/master/README.md
72+
readmeRegexp := regexp.MustCompile(`(?i)^readme\.(markdown)|(mdown)|(mkdn)|(md)|(textile)|(rdoc)|(org)|(creole)|(mediawiki)|(wiki)|(rst)|(asciidoc)|(adoc)|(asc)|(pod)|(txt)`)
73+
74+
// https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/about-readmes#about-readmes
75+
if pathContainsReadme(checkdata.ProjectPath(), readmeRegexp) ||
76+
(checkdata.ProjectPath().Join("docs").Exist() && pathContainsReadme(checkdata.ProjectPath().Join("docs"), readmeRegexp)) ||
77+
(checkdata.ProjectPath().Join(".github").Exist() && pathContainsReadme(checkdata.ProjectPath().Join(".github"), readmeRegexp)) {
78+
return checkresult.Pass, ""
79+
}
80+
81+
return checkresult.Fail, ""
82+
}
83+
84+
// pathContainsReadme checks if the provided path contains a readme file recognized by GitHub.
85+
func pathContainsReadme(path *paths.Path, readmeRegexp *regexp.Regexp) bool {
86+
listing, err := path.ReadDir()
87+
if err != nil {
88+
panic(err)
89+
}
90+
listing.FilterOutDirs()
91+
92+
for _, file := range listing {
93+
if readmeRegexp.MatchString(file.Base()) {
94+
return true
95+
}
96+
}
97+
98+
return false
99+
}

Diff for: check/checkfunctions/library_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,12 @@ func TestRecursiveLibraryWithUtilityFolder(t *testing.T) {
381381

382382
checkLibraryCheckFunction(RecursiveLibraryWithUtilityFolder, testTables, t)
383383
}
384+
385+
func TestMissingReadme(t *testing.T) {
386+
testTables := []libraryCheckFunctionTestTable{
387+
{"Readme", "Readme", checkresult.Pass, ""},
388+
{"No readme", "NoReadme", checkresult.Fail, ""},
389+
}
390+
391+
checkLibraryCheckFunction(MissingReadme, testTables, t)
392+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=NoReadme
2+
version=1.0.0
3+
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
4+
maintainer=Cristian Maglie <[email protected]>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr

Diff for: check/checkfunctions/testdata/libraries/NoReadme/src/NoReadme.h

Whitespace-only changes.

Diff for: check/checkfunctions/testdata/libraries/Readme/README.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=Readme
2+
version=1.0.0
3+
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
4+
maintainer=Cristian Maglie <[email protected]>
5+
sentence=A library that makes coding a web server a breeze.
6+
paragraph=Supports HTTP1.1 and you can do GET and POST.
7+
category=Communication
8+
url=http://example.com/
9+
architectures=avr

Diff for: check/checkfunctions/testdata/libraries/Readme/src/Readme.h

Whitespace-only changes.

0 commit comments

Comments
 (0)