Skip to content

Commit 898b040

Browse files
authored
Merge pull request #20 from per1234/indexer-logs-url
Add list of indexer logs URLs to output
2 parents 9f9696d + 3f09f1b commit 898b040

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

main.go

+25-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ var recommendedOrganizations []string = []string{
5959

6060
// request is the type of the request data.
6161
type request struct {
62-
Type string `json:"type"` // Request type.
63-
Submissions []submissionType `json:"submissions"` // Data for submitted libraries.
64-
IndexEntry string `json:"indexEntry"` // Entry that will be made to the Library Manager index source file when the submission is accepted.
62+
Type string `json:"type"` // Request type.
63+
Submissions []submissionType `json:"submissions"` // Data for submitted libraries.
64+
IndexEntry string `json:"indexEntry"` // Entry that will be made to the Library Manager index source file when the submission is accepted.
65+
IndexerLogsURLs string `json:"indexerLogsURLs"` // List of URLs where the logs from the Library Manager indexer for each submission are available for view.
6566
}
6667

6768
// submissionType is the type of the data for each individual library submitted in the request.
@@ -118,15 +119,20 @@ func main() {
118119

119120
// Process the submissions.
120121
var indexEntries []string
122+
var indexerLogsURLs []string
121123
for _, submissionURL := range submissionURLs {
122124
submission, indexEntry := populateSubmission(submissionURL, listPath)
123125
req.Submissions = append(req.Submissions, submission)
124126
indexEntries = append(indexEntries, indexEntry)
127+
indexerLogsURLs = append(indexerLogsURLs, indexerLogsURL(submission.NormalizedURL))
125128
}
126129

127130
// Assemble the index entry for the submissions.
128131
req.IndexEntry = strings.Join(indexEntries, "%0A")
129132

133+
// Assemble the list of Library Manager indexer logs URLs for the submissions to show in the acceptance message.
134+
req.IndexerLogsURLs = strings.Join(indexerLogsURLs, "%0A")
135+
130136
// Marshal the request data into a JSON document.
131137
var marshalledRequest bytes.Buffer
132138
jsonEncoder := json.NewEncoder(io.Writer(&marshalledRequest))
@@ -359,6 +365,22 @@ func normalizeURL(rawURL *url.URL) url.URL {
359365
}
360366
}
361367

368+
// indexerLogsURL returns the URL where the logs from the Library Manager indexer are available for view.
369+
func indexerLogsURL(normalizedURL string) string {
370+
normalizedURLObject, err := url.Parse(normalizedURL)
371+
if err != nil {
372+
panic(err)
373+
}
374+
375+
indexerLogsURLObject := url.URL{
376+
Scheme: "http",
377+
Host: "downloads.arduino.cc",
378+
Path: "/libraries/logs/" + normalizedURLObject.Host + strings.TrimSuffix(normalizedURLObject.Path, ".git") + "/",
379+
}
380+
381+
return indexerLogsURLObject.String()
382+
}
383+
362384
func uRLIsUnder(childURL url.URL, parentCandidates []string) bool {
363385
for _, parentCandidate := range parentCandidates {
364386
if !strings.HasSuffix(parentCandidate, "/") {

main_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ func Test_normalizeURL(t *testing.T) {
170170
}
171171
}
172172

173+
func Test_indexerLogsURL(t *testing.T) {
174+
testTables := []struct {
175+
testName string
176+
normalizedURL string
177+
expectedIndexerLogsURL string
178+
}{
179+
{"GitHub", "https://github.com/foo/bar.git", "http://downloads.arduino.cc/libraries/logs/github.com/foo/bar/"},
180+
{"GitLab", "https://gitlab.com/yesbotics/libs/arduino/voltmeter.git", "http://downloads.arduino.cc/libraries/logs/gitlab.com/yesbotics/libs/arduino/voltmeter/"},
181+
}
182+
183+
for _, testTable := range testTables {
184+
assert.Equal(t, testTable.expectedIndexerLogsURL, indexerLogsURL(testTable.normalizedURL), testTable.testName)
185+
}
186+
}
187+
173188
func Test_uRLIsUnder(t *testing.T) {
174189
testTables := []struct {
175190
testName string

0 commit comments

Comments
 (0)