Skip to content

Commit

Permalink
Merge pull request #67 from per1234/blank-line-type
Browse files Browse the repository at this point in the history
Assign "other" request type for newline-only diffs
  • Loading branch information
per1234 authored Aug 26, 2021
2 parents 86cc80c + d404219 commit 0de0b65
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ func parseDiff(rawDiff []byte, listName string) (string, string, string, []strin

var requestType string
var arduinoLintLibraryManagerSetting string
if addedCount > 0 && deletedCount == 0 {
if addedCount == 0 && deletedCount == 0 {
requestType = "other"
} else if addedCount > 0 && deletedCount == 0 {
requestType = "submission"
arduinoLintLibraryManagerSetting = "submit"
} else if addedCount == 0 && deletedCount > 0 {
Expand Down
26 changes: 23 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ index cff484d..9f67763 100644
assert.Equal(t, "submission", requestType, testName)
assert.Equal(t, "", requestError, testName)
assert.Equal(t, "submit", arduinoLintLibraryManagerSetting, testName)
assert.ElementsMatch(t, submissionURLs, []string{"https://github.com/foo/bar", "https://github.com/foo/baz"}, testName)
assert.ElementsMatch(t, []string{"https://github.com/foo/bar", "https://github.com/foo/baz"}, submissionURLs, testName)

testName = "Submission w/ no newline at end of file"
diff = []byte(`
Expand Down Expand Up @@ -137,7 +137,7 @@ index cff484d..1b0b80b 100644
assert.Equal(t, "submission", requestType, testName)
assert.Equal(t, "", requestError, testName)
assert.Equal(t, "submit", arduinoLintLibraryManagerSetting, testName)
assert.ElementsMatch(t, submissionURLs, []string{"https://github.com/foo/bar"}, testName)
assert.ElementsMatch(t, []string{"https://github.com/foo/bar"}, submissionURLs, testName)

testName = "Removal"
diff = []byte(`
Expand Down Expand Up @@ -170,7 +170,27 @@ index cff484d..8b401a1 100644
assert.Equal(t, "modification", requestType, testName)
assert.Equal(t, "", requestError, testName)
assert.Equal(t, "update", arduinoLintLibraryManagerSetting, testName)
assert.Equal(t, submissionURLs, []string{"https://github.com/foo/bar"}, testName)
assert.Equal(t, []string{"https://github.com/foo/bar"}, submissionURLs, testName)

testName = "Newline-only"
diff = []byte(`
diff --git a/repositories.txt b/repositories.txt
index d9a6136..ca902d9 100644
--- a/repositories.txt
+++ b/repositories.txt
@@ -1,4 +1,4 @@
https://github.com/firmata/arduino
-
https://github.com/arduino-libraries/Ethernet
https://github.com/lbernstone/plotutils
+
`)

requestType, requestError, arduinoLintLibraryManagerSetting, submissionURLs = parseDiff(diff, "repositories.txt")
assert.Equal(t, "other", requestType, testName)
assert.Equal(t, "", requestError, testName)
assert.Equal(t, "", arduinoLintLibraryManagerSetting, testName)
assert.Nil(t, submissionURLs, testName)
}

func Test_normalizeURL(t *testing.T) {
Expand Down

0 comments on commit 0de0b65

Please sign in to comment.