Skip to content

Commit 578cdeb

Browse files
committed
Address #137
report shows `originalPath`, `modifiedPath`, `path`, `rawPath`, and `gitRepoPath` / `gitFilePath`
1 parent f122082 commit 578cdeb

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

cmd/loaders.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,10 @@ func displayLabelForHTML(raw string) string {
331331
}
332332
return filepath.Base(raw)
333333
}
334+
335+
func sourceLabelForReport(raw string) string {
336+
if isHTTPURL(raw) {
337+
return sanitizeURLLabel(raw)
338+
}
339+
return raw
340+
}

cmd/report.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func runLeftRightReport(left, right string, opts summaryOpts, breakingConfig *wh
7070
defer result.Release()
7171
flat := FlattenReportWithParameterNames(createReport(commits[0]), result.Changerator.ParameterNames)
7272
flat.Commit = nil
73+
flat.OriginalPath = sourceLabelForReport(left)
74+
flat.ModifiedPath = sourceLabelForReport(right)
7375
return flat, nil
7476
}
7577

cmd/report_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ package cmd
55

66
import (
77
"encoding/json"
8+
"net/http"
9+
"net/http/httptest"
810
"os"
911
"path/filepath"
1012
"strings"
@@ -90,11 +92,39 @@ func TestRunLeftRightReport_Success(t *testing.T) {
9092
assert.NotEmpty(t, report.Changes)
9193
assert.NotEmpty(t, report.DateGenerated)
9294
assert.Nil(t, report.Commit)
95+
assert.Equal(t, "../sample-specs/petstorev3-original.json", report.OriginalPath)
96+
assert.Equal(t, "../sample-specs/petstorev3.json", report.ModifiedPath)
9397
assert.Contains(t, report.Summary, "paths")
9498
assert.Equal(t, 30, report.Summary["paths"].Total)
9599
assert.Equal(t, 16, report.Summary["paths"].Breaking)
96100
}
97101

102+
func TestRunLeftRightReport_SanitizesURLSourceMetadata(t *testing.T) {
103+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
104+
if r.URL.Path == "/left.yaml" {
105+
_, _ = w.Write([]byte("openapi: 3.0.3\ninfo:\n title: Left\n version: '1.0'\npaths: {}\n"))
106+
return
107+
}
108+
_, _ = w.Write([]byte("openapi: 3.0.3\ninfo:\n title: Right\n version: '1.1'\npaths:\n /pets:\n get:\n responses:\n \"200\":\n description: ok\n"))
109+
}))
110+
defer server.Close()
111+
112+
leftURL := server.URL + "/left.yaml?token=left-secret#frag"
113+
rightURL := server.URL + "/right.yaml?token=right-secret#frag"
114+
115+
report, err := runLeftRightReport(leftURL, rightURL, summaryOpts{noColor: true}, nil)
116+
117+
require.NoError(t, err)
118+
require.NotNil(t, report)
119+
assert.Equal(t, server.URL+"/left.yaml", report.OriginalPath)
120+
assert.Equal(t, server.URL+"/right.yaml", report.ModifiedPath)
121+
122+
encoded, err := json.Marshal(report)
123+
require.NoError(t, err)
124+
assert.NotContains(t, string(encoded), "left-secret")
125+
assert.NotContains(t, string(encoded), "right-secret")
126+
}
127+
98128
func TestRunLeftRightReport_SummaryIncludesDocumentLevelOpenAPIChanges(t *testing.T) {
99129
dir := t.TempDir()
100130

@@ -222,6 +252,8 @@ func TestReportCommand_GitRefUsesLeftRightMode(t *testing.T) {
222252
})
223253

224254
assert.Contains(t, output, `"changes"`)
255+
assert.Contains(t, output, `"originalPath": "HEAD:sample-specs/petstorev3-original.json"`)
256+
assert.Contains(t, output, `"modifiedPath": "sample-specs/petstorev3.json"`)
225257
assert.Contains(t, output, `"summary"`)
226258
assert.NotContains(t, output, `"reports"`)
227259
}

model/report.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ type Report struct {
7777
type FlatReport struct {
7878
Summary map[string]*reports.Changed `json:"reportSummary"`
7979
Changes []*HashedChange `json:"changes"`
80+
OriginalPath string `json:"originalPath,omitempty"`
81+
ModifiedPath string `json:"modifiedPath,omitempty"`
8082
DateGenerated string `json:"dateGenerated,omitempty"`
8183
Commit *Commit `gorm:"foreignKey:ID" json:"commitDetails,omitempty"`
8284
}

0 commit comments

Comments
 (0)