From 2dac6f8b2d77df0b50e98455efc2aae13fcded7b Mon Sep 17 00:00:00 2001 From: ChanochShayner <57212002+ChanochShayner@users.noreply.github.com> Date: Thu, 14 Dec 2023 10:23:05 +0200 Subject: [PATCH 1/3] Serverless Tags - adjust indentation calculation. (#452) * adjust indentation * adjust indentation just for sls (noy cfn) --- src/common/yaml/yaml_writer.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/yaml/yaml_writer.go b/src/common/yaml/yaml_writer.go index e7aebc00..eac89036 100644 --- a/src/common/yaml/yaml_writer.go +++ b/src/common/yaml/yaml_writer.go @@ -70,12 +70,16 @@ func WriteYAMLFile(readFilePath string, blocks []structure.IBlock, writeFilePath if isCfn { tagIndent += SingleIndent } - resourcesLines = append(resourcesLines, IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], tagIndent)...) + resourcesLines = append(resourcesLines, IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], tagIndent, 0)...) resourcesLines = append(resourcesLines, oldResourceLines[lastIndex+1:]...) continue } oldTagsIndent := ExtractIndentationOfLine(oldResourceLines[oldResourceTagLines.Start-oldResourceLinesRange.Start]) + oldTagsValueIndent := len(ExtractIndentationOfLine(oldResourceLines[oldResourceTagLines.Start-oldResourceLinesRange.Start+1])) - len(oldTagsIndent) + if isCfn { + oldTagsValueIndent = 0 + } if isCfn { oldTagsIndent += SingleIndent } @@ -87,7 +91,7 @@ func WriteYAMLFile(readFilePath string, blocks []structure.IBlock, writeFilePath } else { UpdateExistingSLSTags(tagLines, diff.Updated) } - allNewResourceTagLines := IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], oldTagsIndent) + allNewResourceTagLines := IndentLines(newResourceLines[newResourceTagLineRange.Start+1:newResourceTagLineRange.End+1], oldTagsIndent, oldTagsValueIndent) var netNewResourceLines []string for i := 0; i < len(allNewResourceTagLines); i += linesPerTag { l := allNewResourceTagLines[i] @@ -337,13 +341,19 @@ func findLastNonEmptyLine(fileLines []string, maxIndex int) int { return 0 } -func IndentLines(textLines []string, indent string) []string { +func IndentLines(textLines []string, indent string, valueIndent int) []string { for i, originLine := range textLines { + var blankSpaces string + if valueIndent == 0 { + blankSpaces = SingleIndent + } else { + blankSpaces = strings.Repeat(" ", valueIndent) + } noLeadingWhitespace := strings.TrimLeft(originLine, "\t \n") if strings.Contains(originLine, "- Key") { textLines[i] = indent + noLeadingWhitespace } else { - textLines[i] = indent + SingleIndent + noLeadingWhitespace + textLines[i] = indent + blankSpaces + noLeadingWhitespace } } From e03d6e787001cf002cf995b654d3971b9200c469 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 17 Dec 2023 12:04:14 +0000 Subject: [PATCH 2/3] chore: Updated coverage badge. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23aea785..fce36db2 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -![Coverage](https://img.shields.io/badge/Coverage-81.2%25-brightgreen) +![Coverage](https://img.shields.io/badge/Coverage-81.1%25-brightgreen) [![Maintained by Bridgecrew.io](https://img.shields.io/badge/maintained%20by-bridgecrew.io-blueviolet)](https://bridgecrew.io/?utm_source=github&utm_medium=organic_oss&utm_campaign=yor) ![golangci-lint](https://github.com/bridgecrewio/yor/workflows/tests/badge.svg) [![security](https://github.com/bridgecrewio/yor/actions/workflows/security.yml/badge.svg)](https://github.com/bridgecrewio/yor/actions/workflows/security.yml) From 9667e175d76a06695f5ad67789fce2aed8677451 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 17 Dec 2023 14:48:41 +0200 Subject: [PATCH 3/3] Bump reviewdog/action-golangci-lint from 2.3.1 to 2.5.0 (#446) * Bump reviewdog/action-golangci-lint from 2.3.1 to 2.5.0 Bumps [reviewdog/action-golangci-lint](https://github.com/reviewdog/action-golangci-lint) from 2.3.1 to 2.5.0. - [Release notes](https://github.com/reviewdog/action-golangci-lint/releases) - [Commits](https://github.com/reviewdog/action-golangci-lint/compare/79d32f10b2ea0d4cebb755d849b048c4b40c3d50...94d61e3205b61acf4ddabfeb13c5f8a13eb4167b) --- updated-dependencies: - dependency-name: reviewdog/action-golangci-lint dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] * Update build.yaml * Update test.yaml --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Saar Ettinger --- .github/workflows/build.yaml | 6 +++++- .github/workflows/test.yaml | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 300be0de..daf1cc42 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -80,11 +80,15 @@ jobs: linter: name: golangci-lint runs-on: [self-hosted, public, linux, x64] + permissions: + checks: write + contents: read + pull-requests: write steps: - name: Check out code into the Go module directory uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 - name: golangci-lint - uses: reviewdog/action-golangci-lint@79d32f10b2ea0d4cebb755d849b048c4b40c3d50 # v2 + uses: reviewdog/action-golangci-lint@94d61e3205b61acf4ddabfeb13c5f8a13eb4167b # v2 with: tool_name: golangci-lint fail_on_error: true diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 64f8c672..7a61f7f9 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,10 +29,14 @@ jobs: linter: name: golangci-lint runs-on: ubuntu-latest + permissions: + checks: write + contents: read + pull-requests: write steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 - name: golangci-lint - uses: reviewdog/action-golangci-lint@79d32f10b2ea0d4cebb755d849b048c4b40c3d50 # v2 + uses: reviewdog/action-golangci-lint@94d61e3205b61acf4ddabfeb13c5f8a13eb4167b # v2 with: tool_name: golangci-lint fail_on_error: true