-
Notifications
You must be signed in to change notification settings - Fork 494
feat: Add Handling for OCB In YAML Dependency File #5065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
115210c
5f95916
723810e
03d4d5d
a199978
b0482ae
f7eb61c
67f811c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,8 +49,10 @@ func getCommentMarker(fileType types.FileType) (string, error) { | |
| switch fileType { | ||
| case types.FileTypeMod: | ||
| return "//", nil | ||
| case types.FileTypeOCB: | ||
| return "#", nil | ||
| default: | ||
| return "", fmt.Errorf("unknown file_type %q", fileType) | ||
| return "", fmt.Errorf("unknown file_type %q (expected %q or %q)", fileType, types.FileTypeMod, types.FileTypeOCB) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -67,8 +69,8 @@ func getMarkers(fileType types.FileType) (startMarker, endMarker string, err err | |
|
|
||
| // Upserts the generated block using the markers, or lack thereof, as a guide | ||
| func upsertGeneratedBlock(targetContent, replacement, startMarker, endMarker string) (string, error) { | ||
| startIdx := strings.Index(targetContent, startMarker) | ||
| startFound := startIdx != -1 | ||
| lineStart := strings.Index(targetContent, startMarker) | ||
| startFound := lineStart != -1 | ||
|
Comment on lines
71
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's true 👍 let me give that a shot, sounds like it'd be more readable that way |
||
|
|
||
| if !startFound { | ||
| // No start marker: if the end marker exists anywhere, it's invalid. | ||
|
|
@@ -81,16 +83,28 @@ func upsertGeneratedBlock(targetContent, replacement, startMarker, endMarker str | |
| return targetContent + "\n" + replacement, nil | ||
| } | ||
|
|
||
| searchFrom := startIdx + len(startMarker) | ||
| // Find the start of the line containing the start marker | ||
| for lineStart > 0 && targetContent[lineStart-1] != '\n' { | ||
| lineStart-- | ||
| } | ||
|
|
||
| searchFrom := lineStart + len(startMarker) | ||
|
Comment on lines
+86
to
+91
|
||
| endRel := strings.Index(targetContent[searchFrom:], endMarker) | ||
| if endRel == -1 { | ||
| // Start marker exists without an end marker, which is invalid | ||
| return "", fmt.Errorf("found start marker without end marker") | ||
| } | ||
|
|
||
| endIdx := searchFrom + endRel | ||
| endOfMarker := endIdx + len(endMarker) | ||
| lineEnd := searchFrom + endRel + len(endMarker) | ||
|
|
||
| // Find the end of the line containing the end marker (or end of file) | ||
| for lineEnd < len(targetContent) && targetContent[lineEnd] != '\n' { | ||
| lineEnd++ | ||
| } | ||
| // Include the newline if present | ||
| if lineEnd < len(targetContent) { | ||
| lineEnd++ | ||
| } | ||
|
|
||
| // Replace [startIdx, endOfMarker) with replacement. | ||
| return targetContent[:startIdx] + replacement + targetContent[endOfMarker:], nil | ||
| return targetContent[:lineStart] + replacement + targetContent[lineEnd:], nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # BEGIN GENERATED REPLACES - DO NOT EDIT MANUALLY | ||
| {{- range . }} | ||
| {{- if .Comment }} | ||
| # {{ .Comment }} | ||
| {{- end }} | ||
| - {{ .Dependency }} => {{ .Replacement }} | ||
| {{- end }} | ||
| # END GENERATED REPLACES |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| modules: | ||
| - name: test-collector | ||
| path: test-builder-config.yaml | ||
| file_type: ocb | ||
|
|
||
| replaces: | ||
| - comment: Test replace for example.com/package | ||
| dependency: example.com/package | ||
| replacement: example.com/fork v1.0.0 | ||
|
|
||
| - comment: Another test replace | ||
| dependency: github.com/test/dependency | ||
| replacement: github.com/test/fork v1.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| dist: | ||
| module: github.com/test | ||
| name: test | ||
| description: test distribution | ||
| version: v1.0.0 | ||
|
|
||
| extensions: | ||
| - gomod: go.opentelemetry.io/collector/extension/zpagesextension v0.139.0 | ||
|
|
||
| exporters: | ||
| - gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.139.0 | ||
|
|
||
| receivers: | ||
| - gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.139.0 | ||
|
|
||
| replaces: | ||
| # local replacements | ||
| - github.com/some-dependencys/some-dep => ./some-dep | ||
| # BEGIN GENERATED REPLACES - DO NOT EDIT MANUALLY | ||
| # Test replace for example.com/package | ||
| - example.com/package => example.com/fork v1.0.0 | ||
| # Another test replace | ||
| - github.com/test/dependency => github.com/test/fork v1.0.0 | ||
| # END GENERATED REPLACES |
Uh oh!
There was an error while loading. Please reload this page.