diff --git a/.github/README.md b/.github/README.md index 65646e99..2d448626 100644 --- a/.github/README.md +++ b/.github/README.md @@ -32,7 +32,7 @@ Please see our [support](SUPPORT.md) documentation for further instructions. ## Copyright and License ``` -Copyright (c) 2022 Target Brands, Inc. +Copyright 2019 Target Brands, Inc. ``` -[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) +[Apache License, Version 2.0](../LICENSE) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index c01abac7..77f7afb3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,11 +35,11 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v2 + uses: github/codeql-action/init@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +50,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v2 + uses: github/codeql-action/autobuild@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +64,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 + uses: github/codeql-action/analyze@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2 diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml index 0e132542..3476011c 100644 --- a/.github/workflows/reviewdog.yml +++ b/.github/workflows/reviewdog.yml @@ -12,10 +12,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -23,7 +23,7 @@ jobs: check-latest: true - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 + uses: reviewdog/action-golangci-lint@24d4af2fc93f5b2b296229e8b0c0f658d25707af # v2 with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--config=.golangci.yml" @@ -36,10 +36,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -47,7 +47,7 @@ jobs: check-latest: true - name: golangci-lint - uses: reviewdog/action-golangci-lint@v2 + uses: reviewdog/action-golangci-lint@24d4af2fc93f5b2b296229e8b0c0f658d25707af # v2 with: github_token: ${{ secrets.github_token }} golangci_lint_flags: "--config=.golangci.yml" diff --git a/.github/workflows/schema.yml b/.github/workflows/schema.yml index 7ddc8f72..43ce298b 100644 --- a/.github/workflows/schema.yml +++ b/.github/workflows/schema.yml @@ -13,10 +13,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84e611d7..bb2f4d6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,10 +14,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' @@ -29,7 +29,7 @@ jobs: go test -race -covermode=atomic -coverprofile=coverage.out ./... - name: coverage - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d # v3 with: token: ${{ secrets.CODECOV_TOKEN }} file: coverage.out diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 597095fd..99aa56f0 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -14,10 +14,10 @@ jobs: steps: - name: clone - uses: actions/checkout@v3 + uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4 - name: install go - uses: actions/setup-go@v4 + uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4 with: # use version from go.mod file go-version-file: 'go.mod' diff --git a/.golangci.yml b/.golangci.yml index b0fe9631..ef42aeda 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -35,9 +35,7 @@ linters-settings: # https://github.com/denis-tingaikin/go-header goheader: template: |- - Copyright (c) {{ YEAR }} Target Brands, Inc. All rights reserved. - - Use of this source code is governed by the LICENSE file in this repository. + SPDX-License-Identifier: Apache-2.0 # https://github.com/golang/lint golint: diff --git a/LICENSE b/LICENSE index 3abdb036..1decd39e 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright (c) 2022 Target Brands, Inc. + Copyright 2019 Target Brands, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/Makefile b/Makefile index 9d8365c2..373dbb88 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,4 @@ -# Copyright (c) 2022 Target Brands, Inc. All rights reserved. -# -# Use of this source code is governed by the LICENSE file in this repository. +# SPDX-License-Identifier: Apache-2.0 # The `clean` target is intended to clean the workspace # and prepare the local changes for submission. diff --git a/cmd/schema/main.go b/cmd/schema/main.go index ca9304aa..af57b060 100644 --- a/cmd/schema/main.go +++ b/cmd/schema/main.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //go:build ignore // +build ignore diff --git a/constants/action.go b/constants/action.go index f47fca45..9d4502e9 100644 --- a/constants/action.go +++ b/constants/action.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/badge.go b/constants/badge.go index e08dac4e..b92638ac 100644 --- a/constants/badge.go +++ b/constants/badge.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/compression.go b/constants/compression.go index 624bbf29..6a1d11a6 100644 --- a/constants/compression.go +++ b/constants/compression.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/doc.go b/constants/doc.go index d715cfba..0e748959 100644 --- a/constants/doc.go +++ b/constants/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package constants provides the defined constant types for Vela. // diff --git a/constants/driver.go b/constants/driver.go index 651e450e..e42b924c 100644 --- a/constants/driver.go +++ b/constants/driver.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/event.go b/constants/event.go index 9ffcc0dd..cf72a089 100644 --- a/constants/event.go +++ b/constants/event.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/limit.go b/constants/limit.go index 9a352b99..c905ac04 100644 --- a/constants/limit.go +++ b/constants/limit.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/matcher.go b/constants/matcher.go index 94721c7e..ef4c7947 100644 --- a/constants/matcher.go +++ b/constants/matcher.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/operator.go b/constants/operator.go index 3d0bc20c..f6a20901 100644 --- a/constants/operator.go +++ b/constants/operator.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/pipeline.go b/constants/pipeline.go index ce60015a..f3f49ff3 100644 --- a/constants/pipeline.go +++ b/constants/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/pull.go b/constants/pull.go index 28931802..13167998 100644 --- a/constants/pull.go +++ b/constants/pull.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/queue.go b/constants/queue.go index 1b9b5aef..fe3b8087 100644 --- a/constants/queue.go +++ b/constants/queue.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/repo.go b/constants/repo.go index 08b35ee3..b4368f98 100644 --- a/constants/repo.go +++ b/constants/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/secret.go b/constants/secret.go index 3a63dd3c..13628e95 100644 --- a/constants/secret.go +++ b/constants/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/status.go b/constants/status.go index b75e790a..af206a67 100644 --- a/constants/status.go +++ b/constants/status.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/table.go b/constants/table.go index 07d81d7e..2a73e596 100644 --- a/constants/table.go +++ b/constants/table.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants @@ -9,6 +7,9 @@ const ( // TableBuild defines the table type for the database builds table. TableBuild = "builds" + // TableBuildExecutable defines the table type for the database build_executables table. + TableBuildExecutable = "build_executables" + // TableHook defines the table type for the database hooks table. TableHook = "hooks" diff --git a/constants/token.go b/constants/token.go index a7c6870b..c2b0b12d 100644 --- a/constants/token.go +++ b/constants/token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/visibility.go b/constants/visibility.go index 28873684..af2f35b0 100644 --- a/constants/visibility.go +++ b/constants/visibility.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/worker_status.go b/constants/worker_status.go index 0ed75a59..70d17111 100644 --- a/constants/worker_status.go +++ b/constants/worker_status.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/constants/workspace.go b/constants/workspace.go index 475296cd..9efb1b98 100644 --- a/constants/workspace.go +++ b/constants/workspace.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package constants diff --git a/database/build.go b/database/build.go index 75e7c471..204a5e77 100644 --- a/database/build.go +++ b/database/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/build_executable.go b/database/build_executable.go new file mode 100644 index 00000000..615284ea --- /dev/null +++ b/database/build_executable.go @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: Apache-2.0 + +package database + +import ( + "database/sql" + "encoding/base64" + "errors" + + "github.com/go-vela/types/library" +) + +var ( + // ErrEmptyBuildExecutableBuildID defines the error type when a + // BuildExecutable type has an empty BuildID field provided. + ErrEmptyBuildExecutableBuildID = errors.New("empty build_executable build_id provided") +) + +// BuildExecutable is the database representation of a BuildExecutable. +type BuildExecutable struct { + ID sql.NullInt64 `sql:"id"` + BuildID sql.NullInt64 `sql:"build_id"` + Data []byte `sql:"data"` +} + +// Compress will manipulate the existing data for the +// BuildExecutable by compressing that data. This produces +// a significantly smaller amount of data that is +// stored in the system. +func (b *BuildExecutable) Compress(level int) error { + // compress the database BuildExecutable data + data, err := compress(level, b.Data) + if err != nil { + return err + } + + // overwrite database BuildExecutable data with compressed BuildExecutable data + b.Data = data + + return nil +} + +// Decompress will manipulate the existing data for the +// BuildExecutable by decompressing that data. This allows us +// to have a significantly smaller amount of data that +// is stored in the system. +func (b *BuildExecutable) Decompress() error { + // decompress the database BuildExecutable data + data, err := decompress(b.Data) + if err != nil { + return err + } + + // overwrite compressed BuildExecutable data with decompressed BuildExecutable data + b.Data = data + + return nil +} + +// Decrypt will manipulate the existing executable data by +// base64 decoding that value. Then, a AES-256 cipher +// block is created from the encryption key in order to +// decrypt the base64 decoded secret value. +func (b *BuildExecutable) Decrypt(key string) error { + dst := make([]byte, base64.StdEncoding.DecodedLen(len(b.Data))) + + // base64 decode the encrypted repo hash + n, err := base64.StdEncoding.Decode(dst, b.Data) + if err != nil { + return err + } + + dst = dst[:n] + + // decrypt the base64 decoded executable data + decrypted, err := decrypt(key, dst) + if err != nil { + return err + } + + // set the decrypted executable + b.Data = decrypted + + return nil +} + +// Encrypt will manipulate the existing build executable by +// creating a AES-256 cipher block from the encryption +// key in order to encrypt the build executable. Then, the +// build executable is base64 encoded for transport across +// network boundaries. +func (b *BuildExecutable) Encrypt(key string) error { + // encrypt the executable data + encrypted, err := encrypt(key, b.Data) + if err != nil { + return err + } + + // base64 encode the encrypted executable to make it network safe + dst := make([]byte, base64.StdEncoding.EncodedLen(len(encrypted))) + base64.StdEncoding.Encode(dst, encrypted) + + b.Data = dst + + return nil +} + +// Nullify ensures the valid flag for +// the sql.Null types are properly set. +// +// When a field within the BuildExecutable type is the zero +// value for the field, the valid flag is set to +// false causing it to be NULL in the database. +func (b *BuildExecutable) Nullify() *BuildExecutable { + if b == nil { + return nil + } + + // check if the ID field should be false + if b.ID.Int64 == 0 { + b.ID.Valid = false + } + + // check if the BuildID field should be false + if b.BuildID.Int64 == 0 { + b.BuildID.Valid = false + } + + return b +} + +// ToLibrary converts the BuildExecutable type +// to a library BuildExecutable type. +func (b *BuildExecutable) ToLibrary() *library.BuildExecutable { + buildExecutable := new(library.BuildExecutable) + + buildExecutable.SetID(b.ID.Int64) + buildExecutable.SetBuildID(b.BuildID.Int64) + buildExecutable.SetData(b.Data) + + return buildExecutable +} + +// Validate verifies the necessary fields for +// the BuildExecutable type are populated correctly. +func (b *BuildExecutable) Validate() error { + // verify the BuildID field is populated + if b.BuildID.Int64 <= 0 { + return ErrEmptyBuildExecutableBuildID + } + + return nil +} + +// BuildExecutableFromLibrary converts the library BuildExecutable type +// to a database BuildExecutable type. +func BuildExecutableFromLibrary(c *library.BuildExecutable) *BuildExecutable { + buildExecutable := &BuildExecutable{ + ID: sql.NullInt64{Int64: c.GetID(), Valid: true}, + BuildID: sql.NullInt64{Int64: c.GetBuildID(), Valid: true}, + Data: c.GetData(), + } + + return buildExecutable.Nullify() +} diff --git a/database/build_executable_test.go b/database/build_executable_test.go new file mode 100644 index 00000000..821bca89 --- /dev/null +++ b/database/build_executable_test.go @@ -0,0 +1,455 @@ +// SPDX-License-Identifier: Apache-2.0 + +package database + +import ( + "database/sql" + "reflect" + "testing" + + "github.com/go-vela/types/constants" + "github.com/go-vela/types/library" +) + +func TestDatabase_BuildExecutable_Compress(t *testing.T) { + // setup tests + tests := []struct { + name string + failure bool + level int + buildExecutable *BuildExecutable + want []byte + }{ + { + name: "compression level -1", + failure: false, + level: constants.CompressionNegOne, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 0", + failure: false, + level: constants.CompressionZero, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 1, 0, 108, 1, 147, 254, 10, 123, 32, 10, 32, 32, 32, 32, 34, 105, 100, 34, 58, 32, 34, 115, 116, 101, 112, 95, 110, 97, 109, 101, 34, 44, 10, 32, 32, 32, 32, 34, 118, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 34, 44, 10, 32, 32, 32, 32, 34, 109, 101, 116, 97, 100, 97, 116, 97, 34, 58, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 99, 108, 111, 110, 101, 34, 58, 116, 114, 117, 101, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 91, 34, 115, 116, 101, 112, 115, 34, 44, 34, 115, 101, 114, 118, 105, 99, 101, 115, 34, 44, 34, 115, 101, 99, 114, 101, 116, 115, 34, 93, 125, 44, 10, 32, 32, 32, 32, 34, 119, 111, 114, 107, 101, 114, 34, 58, 123, 125, 44, 10, 32, 32, 32, 32, 34, 115, 116, 101, 112, 115, 34, 58, 91, 10, 32, 32, 32, 32, 32, 32, 32, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 105, 100, 34, 58, 34, 115, 116, 101, 112, 95, 103, 105, 116, 104, 117, 98, 95, 111, 99, 116, 111, 99, 97, 116, 95, 49, 95, 105, 110, 105, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 100, 105, 114, 101, 99, 116, 111, 114, 121, 34, 58, 34, 47, 118, 101, 108, 97, 47, 115, 114, 99, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 103, 105, 116, 104, 117, 98, 47, 111, 99, 116, 111, 99, 97, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 32, 123, 34, 66, 85, 73, 76, 68, 95, 65, 85, 84, 72, 79, 82, 34, 58, 34, 79, 99, 116, 111, 99, 97, 116, 34, 125, 10, 32, 32, 32, 32, 32, 32, 32, 32, 125, 10, 32, 32, 32, 32, 93, 10, 125, 10, 1, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 1", + failure: false, + level: constants.CompressionOne, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 1, 92, 143, 65, 75, 3, 49, 16, 133, 239, 249, 21, 195, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 76, 7, 13, 118, 19, 153, 76, 87, 100, 217, 255, 46, 217, 236, 86, 244, 157, 134, 151, 121, 243, 190, 152, 145, 12, 17, 17, 226, 9, 150, 80, 148, 63, 93, 242, 61, 99, 211, 236, 129, 165, 196, 156, 234, 219, 118, 245, 122, 86, 127, 242, 234, 97, 199, 121, 169, 10, 225, 156, 19, 195, 170, 92, 184, 69, 171, 192, 105, 136, 146, 83, 207, 73, 97, 15, 243, 249, 130, 13, 10, 203, 16, 3, 183, 49, 8, 107, 193, 113, 106, 49, 124, 101, 249, 96, 129, 29, 87, 163, 50, 21, 216, 195, 181, 235, 183, 181, 106, 38, 159, 151, 220, 91, 212, 247, 203, 171, 203, 65, 115, 240, 234, 182, 46, 166, 168, 11, 245, 42, 156, 162, 112, 208, 44, 223, 176, 232, 6, 62, 251, 174, 72, 232, 90, 244, 38, 228, 126, 25, 187, 229, 202, 255, 248, 159, 31, 209, 136, 187, 253, 227, 211, 189, 187, 221, 191, 60, 236, 158, 97, 177, 107, 221, 152, 174, 180, 147, 33, 34, 58, 154, 201, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 2", + failure: false, + level: constants.CompressionTwo, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 146, 111, 222, 183, 205, 232, 26, 231, 156, 67, 238, 224, 29, 170, 210, 103, 40, 177, 39, 108, 172, 30, 72, 106, 230, 242, 251, 109, 123, 233, 122, 210, 216, 69, 141, 240, 227, 252, 211, 204, 167, 19, 23, 130, 87, 57, 147, 161, 115, 75, 101, 200, 194, 165, 167, 162, 240, 135, 249, 124, 197, 6, 149, 100, 200, 137, 44, 38, 33, 173, 56, 78, 203, 226, 23, 203, 7, 9, 252, 120, 41, 12, 242, 135, 117, 235, 111, 117, 53, 55, 241, 183, 172, 239, 231, 215, 192, 73, 57, 69, 13, 219, 144, 75, 214, 197, 122, 21, 237, 178, 80, 82, 150, 111, 120, 180, 3, 157, 98, 91, 37, 181, 134, 222, 36, 238, 151, 216, 46, 87, 174, 241, 127, 47, 114, 35, 238, 246, 143, 79, 247, 225, 118, 255, 242, 176, 123, 134, 199, 206, 182, 49, 173, 182, 150, 142, 205, 212, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 3", + failure: false, + level: constants.CompressionThree, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 118, 222, 123, 223, 54, 163, 107, 156, 115, 14, 185, 131, 119, 168, 74, 159, 161, 196, 158, 176, 49, 123, 32, 169, 153, 203, 239, 219, 246, 226, 245, 164, 177, 139, 26, 225, 199, 249, 104, 62, 76, 39, 46, 4, 175, 114, 38, 139, 206, 46, 149, 33, 11, 151, 158, 138, 194, 31, 230, 250, 138, 13, 42, 201, 144, 19, 153, 76, 66, 90, 113, 156, 150, 197, 47, 150, 15, 18, 248, 241, 98, 88, 200, 31, 214, 214, 191, 213, 149, 220, 192, 223, 178, 190, 159, 95, 3, 39, 229, 20, 53, 108, 67, 46, 89, 23, 234, 21, 169, 203, 66, 73, 89, 190, 225, 209, 14, 116, 138, 109, 149, 212, 90, 244, 38, 113, 191, 200, 118, 105, 185, 142, 255, 251, 145, 27, 113, 183, 127, 124, 186, 15, 183, 251, 151, 135, 221, 51, 60, 118, 182, 141, 105, 165, 53, 117, 108, 166, 230, 39, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 4", + failure: false, + level: constants.CompressionFour, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 204, 14, 26, 236, 102, 100, 50, 93, 145, 101, 255, 187, 52, 73, 87, 244, 54, 124, 51, 223, 203, 75, 55, 155, 206, 24, 99, 16, 7, 88, 131, 172, 244, 233, 146, 31, 9, 155, 138, 39, 146, 28, 57, 93, 118, 219, 43, 27, 73, 253, 224, 213, 195, 206, 5, 20, 24, 78, 156, 8, 86, 229, 76, 245, 172, 80, 74, 83, 20, 78, 35, 37, 133, 61, 148, 248, 140, 13, 50, 201, 20, 3, 213, 49, 8, 105, 198, 113, 105, 233, 95, 44, 31, 36, 176, 243, 21, 84, 201, 30, 214, 212, 223, 87, 203, 254, 210, 188, 22, 127, 139, 250, 126, 126, 117, 28, 148, 131, 87, 183, 117, 49, 69, 109, 173, 215, 243, 33, 10, 5, 101, 249, 134, 69, 63, 209, 201, 247, 89, 66, 95, 213, 155, 192, 99, 27, 251, 150, 242, 95, 255, 243, 35, 51, 227, 110, 255, 248, 116, 239, 110, 247, 47, 15, 187, 103, 88, 236, 154, 181, 172, 86, 157, 142, 221, 210, 253, 4, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 5", + failure: false, + level: constants.CompressionFive, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 6", + failure: false, + level: constants.CompressionSix, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 7", + failure: false, + level: constants.CompressionSeven, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 8", + failure: false, + level: constants.CompressionEight, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + { + name: "compression level 9", + failure: false, + level: constants.CompressionNine, + buildExecutable: &BuildExecutable{Data: testBuildExecutableData()}, + want: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}, + }, + } + + // run tests + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + err := test.buildExecutable.Compress(test.level) + + if test.failure { + if err == nil { + t.Errorf("Compress for %s should have returned err", test.name) + } + + return + } + + if err != nil { + t.Errorf("Compress for %s returned err: %v", test.name, err) + } + + if !reflect.DeepEqual(test.buildExecutable.Data, test.want) { + t.Errorf("Compress for %s is %v, want %v", test.name, test.buildExecutable.Data, string(test.want)) + } + }) + } +} + +func TestDatabase_BuildExecutable_Decompress(t *testing.T) { + // setup tests + tests := []struct { + name string + failure bool + buildExecutable *BuildExecutable + want []byte + }{ + { + name: "compression level -1", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 0", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 1, 0, 108, 1, 147, 254, 10, 123, 32, 10, 32, 32, 32, 32, 34, 105, 100, 34, 58, 32, 34, 115, 116, 101, 112, 95, 110, 97, 109, 101, 34, 44, 10, 32, 32, 32, 32, 34, 118, 101, 114, 115, 105, 111, 110, 34, 58, 32, 34, 49, 34, 44, 10, 32, 32, 32, 32, 34, 109, 101, 116, 97, 100, 97, 116, 97, 34, 58, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 99, 108, 111, 110, 101, 34, 58, 116, 114, 117, 101, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 91, 34, 115, 116, 101, 112, 115, 34, 44, 34, 115, 101, 114, 118, 105, 99, 101, 115, 34, 44, 34, 115, 101, 99, 114, 101, 116, 115, 34, 93, 125, 44, 10, 32, 32, 32, 32, 34, 119, 111, 114, 107, 101, 114, 34, 58, 123, 125, 44, 10, 32, 32, 32, 32, 34, 115, 116, 101, 112, 115, 34, 58, 91, 10, 32, 32, 32, 32, 32, 32, 32, 32, 123, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 105, 100, 34, 58, 34, 115, 116, 101, 112, 95, 103, 105, 116, 104, 117, 98, 95, 111, 99, 116, 111, 99, 97, 116, 95, 49, 95, 105, 110, 105, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 100, 105, 114, 101, 99, 116, 111, 114, 121, 34, 58, 34, 47, 118, 101, 108, 97, 47, 115, 114, 99, 47, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 103, 105, 116, 104, 117, 98, 47, 111, 99, 116, 111, 99, 97, 116, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 34, 101, 110, 118, 105, 114, 111, 110, 109, 101, 110, 116, 34, 58, 32, 123, 34, 66, 85, 73, 76, 68, 95, 65, 85, 84, 72, 79, 82, 34, 58, 34, 79, 99, 116, 111, 99, 97, 116, 34, 125, 10, 32, 32, 32, 32, 32, 32, 32, 32, 125, 10, 32, 32, 32, 32, 93, 10, 125, 10, 1, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 1", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 1, 92, 143, 65, 75, 3, 49, 16, 133, 239, 249, 21, 195, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 76, 7, 13, 118, 19, 153, 76, 87, 100, 217, 255, 46, 217, 236, 86, 244, 157, 134, 151, 121, 243, 190, 152, 145, 12, 17, 17, 226, 9, 150, 80, 148, 63, 93, 242, 61, 99, 211, 236, 129, 165, 196, 156, 234, 219, 118, 245, 122, 86, 127, 242, 234, 97, 199, 121, 169, 10, 225, 156, 19, 195, 170, 92, 184, 69, 171, 192, 105, 136, 146, 83, 207, 73, 97, 15, 243, 249, 130, 13, 10, 203, 16, 3, 183, 49, 8, 107, 193, 113, 106, 49, 124, 101, 249, 96, 129, 29, 87, 163, 50, 21, 216, 195, 181, 235, 183, 181, 106, 38, 159, 151, 220, 91, 212, 247, 203, 171, 203, 65, 115, 240, 234, 182, 46, 166, 168, 11, 245, 42, 156, 162, 112, 208, 44, 223, 176, 232, 6, 62, 251, 174, 72, 232, 90, 244, 38, 228, 126, 25, 187, 229, 202, 255, 248, 159, 31, 209, 136, 187, 253, 227, 211, 189, 187, 221, 191, 60, 236, 158, 97, 177, 107, 221, 152, 174, 180, 147, 33, 34, 58, 154, 201, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 2", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 146, 111, 222, 183, 205, 232, 26, 231, 156, 67, 238, 224, 29, 170, 210, 103, 40, 177, 39, 108, 172, 30, 72, 106, 230, 242, 251, 109, 123, 233, 122, 210, 216, 69, 141, 240, 227, 252, 211, 204, 167, 19, 23, 130, 87, 57, 147, 161, 115, 75, 101, 200, 194, 165, 167, 162, 240, 135, 249, 124, 197, 6, 149, 100, 200, 137, 44, 38, 33, 173, 56, 78, 203, 226, 23, 203, 7, 9, 252, 120, 41, 12, 242, 135, 117, 235, 111, 117, 53, 55, 241, 183, 172, 239, 231, 215, 192, 73, 57, 69, 13, 219, 144, 75, 214, 197, 122, 21, 237, 178, 80, 82, 150, 111, 120, 180, 3, 157, 98, 91, 37, 181, 134, 222, 36, 238, 151, 216, 46, 87, 174, 241, 127, 47, 114, 35, 238, 246, 143, 79, 247, 225, 118, 255, 242, 176, 123, 134, 199, 206, 182, 49, 173, 182, 150, 142, 205, 212, 252, 4, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 3", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 195, 64, 16, 133, 239, 249, 21, 203, 59, 23, 67, 175, 123, 83, 60, 40, 8, 5, 177, 167, 82, 150, 117, 51, 232, 98, 179, 35, 179, 211, 136, 132, 252, 119, 49, 147, 70, 236, 237, 241, 118, 222, 123, 223, 54, 163, 107, 156, 115, 14, 185, 131, 119, 168, 74, 159, 161, 196, 158, 176, 49, 123, 32, 169, 153, 203, 239, 219, 246, 226, 245, 164, 177, 139, 26, 225, 199, 249, 104, 62, 76, 39, 46, 4, 175, 114, 38, 139, 206, 46, 149, 33, 11, 151, 158, 138, 194, 31, 230, 250, 138, 13, 42, 201, 144, 19, 153, 76, 66, 90, 113, 156, 150, 197, 47, 150, 15, 18, 248, 241, 98, 88, 200, 31, 214, 214, 191, 213, 149, 220, 192, 223, 178, 190, 159, 95, 3, 39, 229, 20, 53, 108, 67, 46, 89, 23, 234, 21, 169, 203, 66, 73, 89, 190, 225, 209, 14, 116, 138, 109, 149, 212, 90, 244, 38, 113, 191, 200, 118, 105, 185, 142, 255, 251, 145, 27, 113, 183, 127, 124, 186, 15, 183, 251, 151, 135, 221, 51, 60, 118, 182, 141, 105, 165, 53, 117, 108, 166, 230, 39, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 4", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 23, 151, 94, 115, 83, 60, 40, 8, 5, 177, 167, 82, 66, 204, 14, 26, 236, 102, 100, 50, 93, 145, 101, 255, 187, 52, 73, 87, 244, 54, 124, 51, 223, 203, 75, 55, 155, 206, 24, 99, 16, 7, 88, 131, 172, 244, 233, 146, 31, 9, 155, 138, 39, 146, 28, 57, 93, 118, 219, 43, 27, 73, 253, 224, 213, 195, 206, 5, 20, 24, 78, 156, 8, 86, 229, 76, 245, 172, 80, 74, 83, 20, 78, 35, 37, 133, 61, 148, 248, 140, 13, 50, 201, 20, 3, 213, 49, 8, 105, 198, 113, 105, 233, 95, 44, 31, 36, 176, 243, 21, 84, 201, 30, 214, 212, 223, 87, 203, 254, 210, 188, 22, 127, 139, 250, 126, 126, 117, 28, 148, 131, 87, 183, 117, 49, 69, 109, 173, 215, 243, 33, 10, 5, 101, 249, 134, 69, 63, 209, 201, 247, 89, 66, 95, 213, 155, 192, 99, 27, 251, 150, 242, 95, 255, 243, 35, 51, 227, 110, 255, 248, 116, 239, 110, 247, 47, 15, 187, 103, 88, 236, 154, 181, 172, 86, 157, 142, 221, 210, 253, 4, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 5", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 94, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 6", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 156, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 7", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 8", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + { + name: "compression level 9", + failure: false, + buildExecutable: &BuildExecutable{Data: []byte{120, 218, 92, 143, 65, 75, 3, 49, 16, 133, 239, 251, 43, 194, 59, 47, 46, 189, 230, 166, 120, 80, 16, 10, 98, 79, 165, 132, 152, 29, 52, 216, 205, 200, 100, 186, 34, 203, 254, 119, 113, 147, 110, 105, 111, 143, 47, 249, 94, 94, 154, 201, 52, 198, 24, 131, 216, 195, 26, 100, 165, 111, 151, 252, 64, 104, 11, 30, 73, 114, 228, 244, 127, 182, 57, 179, 129, 212, 247, 94, 61, 236, 180, 128, 5, 134, 35, 39, 130, 85, 57, 81, 123, 161, 148, 198, 40, 156, 6, 74, 10, 187, 95, 234, 51, 90, 100, 146, 49, 6, 42, 49, 8, 105, 198, 97, 174, 237, 63, 44, 95, 36, 176, 211, 25, 20, 201, 238, 215, 214, 203, 171, 235, 242, 50, 252, 35, 234, 231, 233, 221, 113, 80, 14, 94, 221, 198, 197, 20, 21, 237, 245, 245, 62, 10, 5, 101, 249, 133, 69, 55, 210, 209, 119, 89, 66, 87, 212, 187, 192, 67, 141, 93, 109, 185, 213, 175, 126, 100, 38, 60, 236, 158, 95, 30, 221, 253, 238, 237, 105, 251, 10, 139, 109, 181, 230, 213, 42, 233, 208, 204, 205, 95, 0, 0, 0, 255, 255, 225, 62, 100, 105}}, + want: testBuildExecutableData(), + }, + } + + // run tests + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + err := test.buildExecutable.Decompress() + + if test.failure { + if err == nil { + t.Errorf("Decompress for %s should have returned err", test.name) + } + + return + } + + if err != nil { + t.Errorf("Decompress for %s returned err: %v", test.name, err) + } + + if !reflect.DeepEqual(test.buildExecutable.Data, test.want) { + t.Errorf("Decompress for %s is %v, want %v", test.name, string(test.buildExecutable.Data), string(test.want)) + } + }) + } +} + +func TestDatabase_BuildExecutable_Decrypt(t *testing.T) { + // setup types + key := "C639A572E14D5075C526FDDD43E4ECF6" + encrypted := testBuildExecutable() + + err := encrypted.Encrypt(key) + if err != nil { + t.Errorf("unable to encrypt repo: %v", err) + } + + // setup tests + tests := []struct { + failure bool + key string + executable BuildExecutable + }{ + { + failure: false, + key: key, + executable: *encrypted, + }, + { + failure: true, + key: "", + executable: *encrypted, + }, + { + failure: true, + key: key, + executable: *testBuildExecutable(), + }, + } + + // run tests + for _, test := range tests { + err := test.executable.Decrypt(test.key) + + if test.failure { + if err == nil { + t.Errorf("Decrypt should have returned err") + } + + continue + } + + if err != nil { + t.Errorf("Decrypt returned err: %v", err) + } + } +} + +func TestDatabase_BuildExecutable_Encrypt(t *testing.T) { + // setup types + key := "C639A572E14D5075C526FDDD43E4ECF6" + + // setup tests + tests := []struct { + failure bool + key string + executable *BuildExecutable + }{ + { + failure: false, + key: key, + executable: testBuildExecutable(), + }, + { + failure: true, + key: "", + executable: testBuildExecutable(), + }, + } + + // run tests + for _, test := range tests { + err := test.executable.Encrypt(test.key) + + if test.failure { + if err == nil { + t.Errorf("Encrypt should have returned err") + } + + continue + } + + if err != nil { + t.Errorf("Encrypt returned err: %v", err) + } + } +} + +func TestDatabase_BuildExecutable_Nullify(t *testing.T) { + // setup types + var p *BuildExecutable + + want := &BuildExecutable{ + ID: sql.NullInt64{Int64: 0, Valid: false}, + BuildID: sql.NullInt64{Int64: 0, Valid: false}, + } + + // setup tests + tests := []struct { + buildExecutable *BuildExecutable + want *BuildExecutable + }{ + { + buildExecutable: testBuildExecutable(), + want: testBuildExecutable(), + }, + { + buildExecutable: p, + want: nil, + }, + { + buildExecutable: new(BuildExecutable), + want: want, + }, + } + + // run tests + for _, test := range tests { + got := test.buildExecutable.Nullify() + + if !reflect.DeepEqual(got, test.want) { + t.Errorf("Nullify is %v, want %v", got, test.want) + } + } +} + +func TestDatabase_BuildExecutable_ToLibrary(t *testing.T) { + // setup types + want := new(library.BuildExecutable) + + want.SetID(1) + want.SetBuildID(1) + want.SetData(testBuildExecutableData()) + + // run test + got := testBuildExecutable().ToLibrary() + + if !reflect.DeepEqual(got, want) { + t.Errorf("ToLibrary is %v, want %v", got, want) + } +} + +func TestDatabase_BuildExecutable_Validate(t *testing.T) { + // setup tests + tests := []struct { + failure bool + buildExecutable *BuildExecutable + }{ + { + failure: false, + buildExecutable: testBuildExecutable(), + }, + { // no build_id set for buildExecutable + failure: true, + buildExecutable: &BuildExecutable{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + }, + }, + } + + // run tests + for _, test := range tests { + err := test.buildExecutable.Validate() + + if test.failure { + if err == nil { + t.Errorf("Validate should have returned err") + } + + continue + } + + if err != nil { + t.Errorf("Validate returned err: %v", err) + } + } +} + +func TestDatabase_BuildExecutableFromLibrary(t *testing.T) { + // setup types + c := new(library.BuildExecutable) + + c.SetID(1) + c.SetBuildID(1) + c.SetData(testBuildExecutableData()) + + want := testBuildExecutable() + + // run test + got := BuildExecutableFromLibrary(c) + + if !reflect.DeepEqual(got, want) { + t.Errorf("BuildExecutableFromLibrary is %v, want %v", got, want) + } +} + +// testBuildExecutable is a test helper function to create a BuildExecutable +// type with all fields set to a fake value. +func testBuildExecutable() *BuildExecutable { + return &BuildExecutable{ + ID: sql.NullInt64{Int64: 1, Valid: true}, + BuildID: sql.NullInt64{Int64: 1, Valid: true}, + Data: testBuildExecutableData(), + } +} + +// testBuildExecutableData is a test helper function to create the +// content for the Data field for the BuildExecutable type. +func testBuildExecutableData() []byte { + return []byte(` +{ + "id": "step_name", + "version": "1", + "metadata":{ + "clone":true, + "environment":["steps","services","secrets"]}, + "worker":{}, + "steps":[ + { + "id":"step_github_octocat_1_init", + "directory":"/vela/src/github.com/github/octocat", + "environment": {"BUILD_AUTHOR":"Octocat"} + } + ] +} +`) +} diff --git a/database/build_queue.go b/database/build_queue.go index 3fc57639..131b184c 100644 --- a/database/build_queue.go +++ b/database/build_queue.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/build_queue_test.go b/database/build_queue_test.go index 6cbc07de..8ff3c422 100644 --- a/database/build_queue_test.go +++ b/database/build_queue_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/build_test.go b/database/build_test.go index ee512692..972b4cf2 100644 --- a/database/build_test.go +++ b/database/build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -133,8 +131,8 @@ func TestDatabase_Build_ToLibrary(t *testing.T) { want.SetAuthor("OctoKitty") want.SetEmail("OctoKitty@github.com") want.SetLink("https://example.company.com/github/octocat/1") - want.SetBranch("master") - want.SetRef("refs/heads/master") + want.SetBranch("main") + want.SetRef("refs/heads/main") want.SetBaseRef("") want.SetHeadRef("") want.SetHost("example.company.com") @@ -222,8 +220,8 @@ func TestDatabase_BuildFromLibrary(t *testing.T) { b.SetAuthor("OctoKitty") b.SetEmail("OctoKitty@github.com") b.SetLink("https://example.company.com/github/octocat/1") - b.SetBranch("master") - b.SetRef("refs/heads/master") + b.SetBranch("main") + b.SetRef("refs/heads/main") b.SetBaseRef("") b.SetHeadRef("") b.SetHost("example.company.com") @@ -281,8 +279,8 @@ func testBuild() *Build { Author: sql.NullString{String: "OctoKitty", Valid: true}, Email: sql.NullString{String: "OctoKitty@github.com", Valid: true}, Link: sql.NullString{String: "https://example.company.com/github/octocat/1", Valid: true}, - Branch: sql.NullString{String: "master", Valid: true}, - Ref: sql.NullString{String: "refs/heads/master", Valid: true}, + Branch: sql.NullString{String: "main", Valid: true}, + Ref: sql.NullString{String: "refs/heads/main", Valid: true}, BaseRef: sql.NullString{String: "", Valid: false}, HeadRef: sql.NullString{String: "", Valid: false}, Host: sql.NullString{String: "example.company.com", Valid: true}, diff --git a/database/compression.go b/database/compression.go index 19138091..d6a399aa 100644 --- a/database/compression.go +++ b/database/compression.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/compression_test.go b/database/compression_test.go index 033b69b0..9133d9cf 100644 --- a/database/compression_test.go +++ b/database/compression_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/context.go b/database/context.go index e5354e1c..a1d1b0cc 100644 --- a/database/context.go +++ b/database/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/context_test.go b/database/context_test.go index c6cbb19d..a5a02b11 100644 --- a/database/context_test.go +++ b/database/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/doc.go b/database/doc.go index 3705e45b..38a39f75 100644 --- a/database/doc.go +++ b/database/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package database provides the defined database types for Vela. // diff --git a/database/encryption.go b/database/encryption.go index 358cef12..7bf20433 100644 --- a/database/encryption.go +++ b/database/encryption.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/encryption_test.go b/database/encryption_test.go index e7c703af..3e2786d6 100644 --- a/database/encryption_test.go +++ b/database/encryption_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/hook.go b/database/hook.go index d737d090..6a10f5d1 100644 --- a/database/hook.go +++ b/database/hook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/hook_test.go b/database/hook_test.go index f5b9f6e7..9247ba0d 100644 --- a/database/hook_test.go +++ b/database/hook_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -75,7 +73,7 @@ func TestDatabase_Hook_ToLibrary(t *testing.T) { want.SetHost("github.com") want.SetEvent("push") want.SetEventAction("") - want.SetBranch("master") + want.SetBranch("main") want.SetError("") want.SetStatus("success") want.SetLink("https://github.com/github/octocat/settings/hooks/1") @@ -91,7 +89,7 @@ func TestDatabase_Hook_ToLibrary(t *testing.T) { Host: sql.NullString{String: "github.com", Valid: true}, Event: sql.NullString{String: "push", Valid: true}, EventAction: sql.NullString{String: "", Valid: true}, - Branch: sql.NullString{String: "master", Valid: true}, + Branch: sql.NullString{String: "main", Valid: true}, Error: sql.NullString{String: "", Valid: true}, Status: sql.NullString{String: "success", Valid: true}, Link: sql.NullString{String: "https://github.com/github/octocat/settings/hooks/1", Valid: true}, @@ -184,7 +182,7 @@ func TestDatabase_HookFromLibrary(t *testing.T) { Host: sql.NullString{String: "github.com", Valid: true}, Event: sql.NullString{String: "pull_request", Valid: true}, EventAction: sql.NullString{String: "opened", Valid: true}, - Branch: sql.NullString{String: "master", Valid: true}, + Branch: sql.NullString{String: "main", Valid: true}, Error: sql.NullString{String: "", Valid: false}, Status: sql.NullString{String: "success", Valid: true}, Link: sql.NullString{String: "https://github.com/github/octocat/settings/hooks/1", Valid: true}, @@ -201,7 +199,7 @@ func TestDatabase_HookFromLibrary(t *testing.T) { h.SetHost("github.com") h.SetEvent("pull_request") h.SetEventAction("opened") - h.SetBranch("master") + h.SetBranch("main") h.SetError("") h.SetStatus("success") h.SetLink("https://github.com/github/octocat/settings/hooks/1") @@ -228,7 +226,7 @@ func testHook() *Hook { Host: sql.NullString{String: "github.com", Valid: true}, Event: sql.NullString{String: "push", Valid: true}, EventAction: sql.NullString{String: "", Valid: false}, - Branch: sql.NullString{String: "master", Valid: true}, + Branch: sql.NullString{String: "main", Valid: true}, Error: sql.NullString{String: "", Valid: false}, Status: sql.NullString{String: "success", Valid: true}, Link: sql.NullString{String: "https://github.com/github/octocat/settings/hooks/1", Valid: true}, diff --git a/database/log.go b/database/log.go index e35d696c..9afa1350 100644 --- a/database/log.go +++ b/database/log.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/log_test.go b/database/log_test.go index b30d51ef..c45fdc61 100644 --- a/database/log_test.go +++ b/database/log_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/pipeline.go b/database/pipeline.go index 292b9c2c..21936294 100644 --- a/database/pipeline.go +++ b/database/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/pipeline_test.go b/database/pipeline_test.go index 3d84e4e5..3e8ceb12 100644 --- a/database/pipeline_test.go +++ b/database/pipeline_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -278,7 +276,7 @@ func TestDatabase_Pipeline_ToLibrary(t *testing.T) { want.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") want.SetFlavor("large") want.SetPlatform("docker") - want.SetRef("refs/heads/master") + want.SetRef("refs/heads/main") want.SetType(constants.PipelineTypeYAML) want.SetVersion("1") want.SetExternalSecrets(false) @@ -312,7 +310,7 @@ func TestDatabase_Pipeline_Validate(t *testing.T) { pipeline: &Pipeline{ ID: sql.NullInt64{Int64: 1, Valid: true}, RepoID: sql.NullInt64{Int64: 1, Valid: true}, - Ref: sql.NullString{String: "refs/heads/master", Valid: true}, + Ref: sql.NullString{String: "refs/heads/main", Valid: true}, Type: sql.NullString{String: constants.PipelineTypeYAML, Valid: true}, Version: sql.NullString{String: "1", Valid: true}, }, @@ -332,7 +330,7 @@ func TestDatabase_Pipeline_Validate(t *testing.T) { pipeline: &Pipeline{ ID: sql.NullInt64{Int64: 1, Valid: true}, Commit: sql.NullString{String: "48afb5bdc41ad69bf22588491333f7cf71135163", Valid: true}, - Ref: sql.NullString{String: "refs/heads/master", Valid: true}, + Ref: sql.NullString{String: "refs/heads/main", Valid: true}, Type: sql.NullString{String: constants.PipelineTypeYAML, Valid: true}, Version: sql.NullString{String: "1", Valid: true}, }, @@ -343,7 +341,7 @@ func TestDatabase_Pipeline_Validate(t *testing.T) { ID: sql.NullInt64{Int64: 1, Valid: true}, RepoID: sql.NullInt64{Int64: 1, Valid: true}, Commit: sql.NullString{String: "48afb5bdc41ad69bf22588491333f7cf71135163", Valid: true}, - Ref: sql.NullString{String: "refs/heads/master", Valid: true}, + Ref: sql.NullString{String: "refs/heads/main", Valid: true}, Version: sql.NullString{String: "1", Valid: true}, }, }, @@ -353,7 +351,7 @@ func TestDatabase_Pipeline_Validate(t *testing.T) { ID: sql.NullInt64{Int64: 1, Valid: true}, RepoID: sql.NullInt64{Int64: 1, Valid: true}, Commit: sql.NullString{String: "48afb5bdc41ad69bf22588491333f7cf71135163", Valid: true}, - Ref: sql.NullString{String: "refs/heads/master", Valid: true}, + Ref: sql.NullString{String: "refs/heads/main", Valid: true}, Type: sql.NullString{String: constants.PipelineTypeYAML, Valid: true}, }, @@ -387,7 +385,7 @@ func TestDatabase_PipelineFromLibrary(t *testing.T) { p.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") p.SetFlavor("large") p.SetPlatform("docker") - p.SetRef("refs/heads/master") + p.SetRef("refs/heads/main") p.SetType(constants.PipelineTypeYAML) p.SetVersion("1") p.SetExternalSecrets(false) @@ -417,7 +415,7 @@ func testPipeline() *Pipeline { Commit: sql.NullString{String: "48afb5bdc41ad69bf22588491333f7cf71135163", Valid: true}, Flavor: sql.NullString{String: "large", Valid: true}, Platform: sql.NullString{String: "docker", Valid: true}, - Ref: sql.NullString{String: "refs/heads/master", Valid: true}, + Ref: sql.NullString{String: "refs/heads/main", Valid: true}, Type: sql.NullString{String: constants.PipelineTypeYAML, Valid: true}, Version: sql.NullString{String: "1", Valid: true}, ExternalSecrets: sql.NullBool{Bool: false, Valid: true}, diff --git a/database/repo.go b/database/repo.go index 6b058d66..a0e12c35 100644 --- a/database/repo.go +++ b/database/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/repo_test.go b/database/repo_test.go index 2a6d6f6f..f5f24966 100644 --- a/database/repo_test.go +++ b/database/repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -163,7 +161,7 @@ func TestDatabase_Repo_ToLibrary(t *testing.T) { want.SetFullName("github/octocat") want.SetLink("https://github.com/github/octocat") want.SetClone("https://github.com/github/octocat.git") - want.SetBranch("master") + want.SetBranch("main") want.SetTopics([]string{"cloud", "security"}) want.SetBuildLimit(10) want.SetTimeout(30) @@ -316,7 +314,7 @@ func TestDatabase_RepoFromLibrary(t *testing.T) { r.SetFullName("github/octocat") r.SetLink("https://github.com/github/octocat") r.SetClone("https://github.com/github/octocat.git") - r.SetBranch("master") + r.SetBranch("main") r.SetTopics([]string{"cloud", "security"}) r.SetBuildLimit(10) r.SetTimeout(30) @@ -355,7 +353,7 @@ func testRepo() *Repo { FullName: sql.NullString{String: "github/octocat", Valid: true}, Link: sql.NullString{String: "https://github.com/github/octocat", Valid: true}, Clone: sql.NullString{String: "https://github.com/github/octocat.git", Valid: true}, - Branch: sql.NullString{String: "master", Valid: true}, + Branch: sql.NullString{String: "main", Valid: true}, Topics: []string{"cloud", "security"}, BuildLimit: sql.NullInt64{Int64: 10, Valid: true}, Timeout: sql.NullInt64{Int64: 30, Valid: true}, diff --git a/database/sanitize.go b/database/sanitize.go index 8d4443b9..01bef23d 100644 --- a/database/sanitize.go +++ b/database/sanitize.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/sanitize_test.go b/database/sanitize_test.go index 4df009af..24d2f105 100644 --- a/database/sanitize_test.go +++ b/database/sanitize_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/schedule.go b/database/schedule.go index 2000f4f8..4f26b278 100644 --- a/database/schedule.go +++ b/database/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -38,6 +36,7 @@ type Schedule struct { UpdatedAt sql.NullInt64 `sql:"updated_at"` UpdatedBy sql.NullString `sql:"updated_by"` ScheduledAt sql.NullInt64 `sql:"scheduled_at"` + Branch sql.NullString `sql:"branch"` } // ScheduleFromLibrary converts the library.Schedule type to a database Schedule type. @@ -53,6 +52,7 @@ func ScheduleFromLibrary(s *library.Schedule) *Schedule { UpdatedAt: sql.NullInt64{Int64: s.GetUpdatedAt(), Valid: true}, UpdatedBy: sql.NullString{String: s.GetUpdatedBy(), Valid: true}, ScheduledAt: sql.NullInt64{Int64: s.GetScheduledAt(), Valid: true}, + Branch: sql.NullString{String: s.GetBranch(), Valid: true}, } return schedule.Nullify() @@ -87,6 +87,8 @@ func (s *Schedule) Nullify() *Schedule { s.UpdatedBy.Valid = len(s.UpdatedBy.String) != 0 // check if the ScheduledAt field should be valid s.ScheduledAt.Valid = s.ScheduledAt.Int64 != 0 + // check if the Branch field should be valid + s.Branch.Valid = len(s.Branch.String) != 0 return s } @@ -104,6 +106,7 @@ func (s *Schedule) ToLibrary() *library.Schedule { UpdatedAt: &s.UpdatedAt.Int64, UpdatedBy: &s.UpdatedBy.String, ScheduledAt: &s.ScheduledAt.Int64, + Branch: &s.Branch.String, } } diff --git a/database/schedule_test.go b/database/schedule_test.go index ee1a06dd..d7ff78aa 100644 --- a/database/schedule_test.go +++ b/database/schedule_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database @@ -25,6 +23,7 @@ func TestDatabase_ScheduleFromLibrary(t *testing.T) { s.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) s.SetUpdatedBy("user2") s.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) + s.SetBranch("main") want := testSchedule() @@ -59,6 +58,7 @@ func TestDatabase_Schedule_Nullify(t *testing.T) { UpdatedAt: sql.NullInt64{Int64: 0, Valid: false}, UpdatedBy: sql.NullString{String: "", Valid: false}, ScheduledAt: sql.NullInt64{Int64: 0, Valid: false}, + Branch: sql.NullString{String: "", Valid: false}, }, }, { @@ -90,6 +90,7 @@ func TestDatabase_Schedule_ToLibrary(t *testing.T) { want.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) want.SetUpdatedBy("user2") want.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) + want.SetBranch("main") got := testSchedule().ToLibrary() if !reflect.DeepEqual(got, want) { @@ -176,5 +177,6 @@ func testSchedule() *Schedule { UpdatedAt: sql.NullInt64{Int64: time.Now().Add(time.Hour * 1).UTC().Unix(), Valid: true}, UpdatedBy: sql.NullString{String: "user2", Valid: true}, ScheduledAt: sql.NullInt64{Int64: time.Now().Add(time.Hour * 2).UTC().Unix(), Valid: true}, + Branch: sql.NullString{String: "main", Valid: true}, } } diff --git a/database/secret.go b/database/secret.go index 2816f99f..c955fd96 100644 --- a/database/secret.go +++ b/database/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/secret_test.go b/database/secret_test.go index 2bff5c81..584faa80 100644 --- a/database/secret_test.go +++ b/database/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/service.go b/database/service.go index ab38abc2..651aef30 100644 --- a/database/service.go +++ b/database/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/service_test.go b/database/service_test.go index 36d57b18..0f149d35 100644 --- a/database/service_test.go +++ b/database/service_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/step.go b/database/step.go index e09dc8f2..318407e1 100644 --- a/database/step.go +++ b/database/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/step_test.go b/database/step_test.go index fd254032..90d10a51 100644 --- a/database/step_test.go +++ b/database/step_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/user.go b/database/user.go index f8013f16..1e312755 100644 --- a/database/user.go +++ b/database/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/user_test.go b/database/user_test.go index 5c7c9cf5..fa3ae5d5 100644 --- a/database/user_test.go +++ b/database/user_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/worker.go b/database/worker.go index ae445c01..59c2f343 100644 --- a/database/worker.go +++ b/database/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/database/worker_test.go b/database/worker_test.go index a6aec4ce..7f48699a 100644 --- a/database/worker_test.go +++ b/database/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package database diff --git a/errors.go b/errors.go index 40e9a6a0..a3c7b919 100644 --- a/errors.go +++ b/errors.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types diff --git a/errors_test.go b/errors_test.go index fcf3bf25..4c1c7b3d 100644 --- a/errors_test.go +++ b/errors_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types diff --git a/go.mod b/go.mod index b390f929..9f9eabf2 100644 --- a/go.mod +++ b/go.mod @@ -1,21 +1,21 @@ module github.com/go-vela/types -go 1.19 +go 1.21 require ( - github.com/adhocore/gronx v1.6.3 + github.com/adhocore/gronx v1.6.6 github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 github.com/drone/envsubst v1.0.3 github.com/ghodss/yaml v1.0.0 github.com/lib/pq v1.10.9 - github.com/microcosm-cc/bluemonday v1.0.24 + github.com/microcosm-cc/bluemonday v1.0.25 ) require ( github.com/aymerick/douceur v0.2.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/kr/pretty v0.2.0 // indirect - golang.org/x/net v0.10.0 // indirect + golang.org/x/net v0.12.0 // indirect gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/yaml.v2 v2.3.0 // indirect ) diff --git a/go.sum b/go.sum index 1aaf12af..455c1602 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/adhocore/gronx v1.6.3 h1:bnm5vieTrY3QQPpsfB0hrAaeaHDpuZTUC2LLCVMLe9c= -github.com/adhocore/gronx v1.6.3/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg= +github.com/adhocore/gronx v1.6.6 h1:Gk1OAP4CCSs2/i3f7HHwB2tX/EtYP3TzzWSHvesTR4k= +github.com/adhocore/gronx v1.6.6/go.mod h1:7oUY1WAU8rEJWmAxXR2DN0JaO4gi9khSgKjiRypqteg= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4= github.com/buildkite/yaml v0.0.0-20181016232759-0caa5f0796e3 h1:q+sMKdA6L8LyGVudTkpGoC73h6ak2iWSPFiFo/pFOU8= @@ -19,10 +19,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= -github.com/microcosm-cc/bluemonday v1.0.24 h1:NGQoPtwGVcbGkKfvyYk1yRqknzBuoMiUrO6R7uFTPlw= -github.com/microcosm-cc/bluemonday v1.0.24/go.mod h1:ArQySAMps0790cHSkdPEJ7bGkF2VePWH773hsJNSHf8= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +github.com/microcosm-cc/bluemonday v1.0.25 h1:4NEwSfiJ+Wva0VxN5B8OwMicaJvD8r9tlJWm9rtloEg= +github.com/microcosm-cc/bluemonday v1.0.25/go.mod h1:ZIOjCQp1OrzBBPIJmfX4qDYFuhU02nx4bn030ixfHLE= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/item.go b/item.go index 972d4c97..55f8ad0b 100644 --- a/item.go +++ b/item.go @@ -1,34 +1,29 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types import ( "github.com/go-vela/types/library" - "github.com/go-vela/types/pipeline" ) // ItemVersion allows the worker to detect items that were queued before an Vela server // upgrade or downgrade, so it can handle such stale data gracefully. // For example, the worker could fail a stale build or ask the server to recompile it. // This is not a public API and is unrelated to the version key in pipeline yaml. -const ItemVersion uint64 = 1 +const ItemVersion uint64 = 2 // Item is the queue representation of an item to publish to the queue. type Item struct { - Build *library.Build `json:"build"` - Pipeline *pipeline.Build `json:"pipeline"` - Repo *library.Repo `json:"repo"` - User *library.User `json:"user"` + Build *library.Build `json:"build"` + Repo *library.Repo `json:"repo"` + User *library.User `json:"user"` // The 0-value is the implicit ItemVersion for queued Items that pre-date adding the field. ItemVersion uint64 `json:"item_version"` } -// ToItem creates a queue item from a pipeline, build, repo and user. -func ToItem(p *pipeline.Build, b *library.Build, r *library.Repo, u *library.User) *Item { +// ToItem creates a queue item from a build, repo and user. +func ToItem(b *library.Build, r *library.Repo, u *library.User) *Item { return &Item{ - Pipeline: p, Build: b, Repo: r, User: u, diff --git a/item_test.go b/item_test.go index ebb9e78b..846463de 100644 --- a/item_test.go +++ b/item_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types @@ -9,7 +7,6 @@ import ( "testing" "github.com/go-vela/types/library" - "github.com/go-vela/types/pipeline" ) func TestTypes_ToItem(t *testing.T) { @@ -42,26 +39,6 @@ func TestTypes_ToItem(t *testing.T) { Ref: &str, BaseRef: &str, } - p := &pipeline.Build{ - Version: "v1", - Stages: pipeline.StageSlice{ - &pipeline.Stage{ - Name: str, - Steps: pipeline.ContainerSlice{ - &pipeline.Container{ - Image: "alpine", - Name: str, - }, - }, - }, - }, - Steps: pipeline.ContainerSlice{ - &pipeline.Container{ - Image: "alpine", - Name: str, - }, - }, - } r := &library.Repo{ ID: &num64, UserID: &num64, @@ -89,26 +66,6 @@ func TestTypes_ToItem(t *testing.T) { Admin: &booL, } want := &Item{ - Pipeline: &pipeline.Build{ - Version: "v1", - Stages: pipeline.StageSlice{ - &pipeline.Stage{ - Name: str, - Steps: pipeline.ContainerSlice{ - &pipeline.Container{ - Image: "alpine", - Name: str, - }, - }, - }, - }, - Steps: pipeline.ContainerSlice{ - &pipeline.Container{ - Image: "alpine", - Name: str, - }, - }, - }, Build: &library.Build{ ID: &num64, RepoID: &num64, @@ -163,7 +120,7 @@ func TestTypes_ToItem(t *testing.T) { } // run test - got := ToItem(p, b, r, u) + got := ToItem(b, r, u) if !reflect.DeepEqual(got, want) { t.Errorf("ToItem is %v, want %v", got, want) diff --git a/library/build.go b/library/build.go index 254c1d16..34edee9d 100644 --- a/library/build.go +++ b/library/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/build_executable.go b/library/build_executable.go new file mode 100644 index 00000000..a2e0cff4 --- /dev/null +++ b/library/build_executable.go @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: Apache-2.0 + +package library + +import ( + "fmt" +) + +// BuildExecutable is the library representation of a BuildExecutable. +// +// swagger:model BuildExecutable +type BuildExecutable struct { + ID *int64 `json:"id,omitempty"` + BuildID *int64 `json:"build_id,omitempty"` + // swagger:strfmt base64 + Data *[]byte `json:"data,omitempty"` +} + +// GetID returns the ID field. +// +// When the provided BuildExecutable type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (b *BuildExecutable) GetID() int64 { + // return zero value if BuildExecutable type or ID field is nil + if b == nil || b.ID == nil { + return 0 + } + + return *b.ID +} + +// GetBuildID returns the BuildID field. +// +// When the provided BuildExecutable type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (b *BuildExecutable) GetBuildID() int64 { + // return zero value if BuildExecutable type or BuildID field is nil + if b == nil || b.BuildID == nil { + return 0 + } + + return *b.BuildID +} + +// GetData returns the Data field. +// +// When the provided BuildExecutable type is nil, or the field within +// the type is nil, it returns the zero value for the field. +func (b *BuildExecutable) GetData() []byte { + // return zero value if BuildExecutable type or Data field is nil + if b == nil || b.Data == nil { + return []byte{} + } + + return *b.Data +} + +// SetID sets the ID field. +// +// When the provided BuildExecutable type is nil, it +// will set nothing and immediately return. +func (b *BuildExecutable) SetID(v int64) { + // return if BuildExecutable type is nil + if b == nil { + return + } + + b.ID = &v +} + +// SetBuildID sets the BuildID field. +// +// When the provided BuildExecutable type is nil, it +// will set nothing and immediately return. +func (b *BuildExecutable) SetBuildID(v int64) { + // return if BuildExecutable type is nil + if b == nil { + return + } + + b.BuildID = &v +} + +// SetData sets the Data field. +// +// When the provided BuildExecutable type is nil, it +// will set nothing and immediately return. +func (b *BuildExecutable) SetData(v []byte) { + // return if Log type is nil + if b == nil { + return + } + + b.Data = &v +} + +// String implements the Stringer interface for the BuildExecutable type. +func (b *BuildExecutable) String() string { + return fmt.Sprintf(`{ + ID: %d, + BuildID: %d, + Data: %s, +}`, + b.GetID(), + b.GetBuildID(), + b.GetData(), + ) +} diff --git a/library/build_executable_test.go b/library/build_executable_test.go new file mode 100644 index 00000000..9f9be60f --- /dev/null +++ b/library/build_executable_test.go @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: Apache-2.0 + +package library + +import ( + "fmt" + "reflect" + "testing" +) + +func TestLibrary_BuildExecutable_Getters(t *testing.T) { + // setup tests + tests := []struct { + buildExecutable *BuildExecutable + want *BuildExecutable + }{ + { + buildExecutable: testBuildExecutable(), + want: testBuildExecutable(), + }, + { + buildExecutable: new(BuildExecutable), + want: new(BuildExecutable), + }, + } + + // run tests + for _, test := range tests { + if test.buildExecutable.GetID() != test.want.GetID() { + t.Errorf("GetID is %v, want %v", test.buildExecutable.GetID(), test.want.GetID()) + } + + if test.buildExecutable.GetBuildID() != test.want.GetBuildID() { + t.Errorf("GetBuildID is %v, want %v", test.buildExecutable.GetBuildID(), test.want.GetBuildID()) + } + + if !reflect.DeepEqual(test.buildExecutable.GetData(), test.want.GetData()) { + t.Errorf("GetData is %v, want %v", test.buildExecutable.GetData(), test.want.GetData()) + } + } +} + +func TestLibrary_BuildExecutable_Setters(t *testing.T) { + // setup types + var bExecutable *BuildExecutable + + // setup tests + tests := []struct { + buildExecutable *BuildExecutable + want *BuildExecutable + }{ + { + buildExecutable: testBuildExecutable(), + want: testBuildExecutable(), + }, + { + buildExecutable: bExecutable, + want: new(BuildExecutable), + }, + } + + // run tests + for _, test := range tests { + test.buildExecutable.SetID(test.want.GetID()) + test.buildExecutable.SetBuildID(test.want.GetBuildID()) + test.buildExecutable.SetData(test.want.GetData()) + + if test.buildExecutable.GetID() != test.want.GetID() { + t.Errorf("SetID is %v, want %v", test.buildExecutable.GetID(), test.want.GetID()) + } + + if test.buildExecutable.GetBuildID() != test.want.GetBuildID() { + t.Errorf("SetRepoID is %v, want %v", test.buildExecutable.GetBuildID(), test.want.GetBuildID()) + } + + if !reflect.DeepEqual(test.buildExecutable.GetData(), test.want.GetData()) { + t.Errorf("SetData is %v, want %v", test.buildExecutable.GetData(), test.want.GetData()) + } + } +} + +func TestLibrary_BuildExecutable_String(t *testing.T) { + // setup types + bExecutable := testBuildExecutable() + + want := fmt.Sprintf(`{ + ID: %d, + BuildID: %d, + Data: %s, +}`, + bExecutable.GetID(), + bExecutable.GetBuildID(), + bExecutable.GetData(), + ) + + // run test + got := bExecutable.String() + + if !reflect.DeepEqual(got, want) { + t.Errorf("String is %v, want %v", got, want) + } +} + +// testBuildExecutable is a test helper function to create a Pipeline +// type with all fields set to a fake value. +func testBuildExecutable() *BuildExecutable { + p := new(BuildExecutable) + + p.SetID(1) + p.SetBuildID(1) + p.SetData(testBuildExecutableData()) + + return p +} + +// testBuildExecutableData is a test helper function to create the +// content for the Data field for the Pipeline type. +func testBuildExecutableData() []byte { + return []byte(` +{ + "id": "step_name", + "version": "1", + "metadata":{ + "clone":true, + "environment":["steps","services","secrets"]}, + "worker":{}, + "steps":[ + { + "id":"step_github_octocat_1_init", + "directory":"/vela/src/github.com/github/octocat", + "environment": {"BUILD_AUTHOR":"Octocat"} + } + ] +} +`) +} diff --git a/library/build_queue.go b/library/build_queue.go index d63e0aaa..64ab0587 100644 --- a/library/build_queue.go +++ b/library/build_queue.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore false positive with template.go package library diff --git a/library/build_queue_test.go b/library/build_queue_test.go index 6d7735f2..fc96d987 100644 --- a/library/build_queue_test.go +++ b/library/build_queue_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/build_test.go b/library/build_test.go index d87de4df..64e4c5ca 100644 --- a/library/build_test.go +++ b/library/build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -91,7 +89,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "VELA_BUILD_BASE_REF": "", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_BUILD_CHANNEL": "TODO", "VELA_BUILD_CLONE": "https://github.com/github/octocat.git", "VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -105,7 +103,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_MESSAGE": "First commit...", "VELA_BUILD_NUMBER": "1", "VELA_BUILD_PARENT": "1", - "VELA_BUILD_REF": "refs/heads/master", + "VELA_BUILD_REF": "refs/heads/main", "VELA_BUILD_RUNTIME": "docker", "VELA_BUILD_SENDER": "OctoKitty", "VELA_BUILD_STARTED": "1563474078", @@ -116,7 +114,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_AUTHOR": "OctoKitty", "BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "BUILD_BASE_REF": "", - "BUILD_BRANCH": "master", + "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", "BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -128,7 +126,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_MESSAGE": "First commit...", "BUILD_NUMBER": "1", "BUILD_PARENT": "1", - "BUILD_REF": "refs/heads/master", + "BUILD_REF": "refs/heads/main", "BUILD_SENDER": "OctoKitty", "BUILD_STARTED": "1563474078", "BUILD_SOURCE": "https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163", @@ -143,7 +141,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "VELA_BUILD_BASE_REF": "", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_BUILD_CHANNEL": "TODO", "VELA_BUILD_CLONE": "https://github.com/github/octocat.git", "VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -170,7 +168,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_AUTHOR": "OctoKitty", "BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "BUILD_BASE_REF": "", - "BUILD_BRANCH": "master", + "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", "BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -198,7 +196,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "VELA_BUILD_BASE_REF": "", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_BUILD_CHANNEL": "TODO", "VELA_BUILD_CLONE": "https://github.com/github/octocat.git", "VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -212,7 +210,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_MESSAGE": "First commit...", "VELA_BUILD_NUMBER": "1", "VELA_BUILD_PARENT": "1", - "VELA_BUILD_REF": "refs/heads/master", + "VELA_BUILD_REF": "refs/heads/main", "VELA_BUILD_RUNTIME": "docker", "VELA_BUILD_SENDER": "OctoKitty", "VELA_BUILD_STARTED": "1563474078", @@ -226,7 +224,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_AUTHOR": "OctoKitty", "BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "BUILD_BASE_REF": "", - "BUILD_BRANCH": "master", + "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", "BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -238,7 +236,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_MESSAGE": "First commit...", "BUILD_NUMBER": "1", "BUILD_PARENT": "1", - "BUILD_REF": "refs/heads/master", + "BUILD_REF": "refs/heads/main", "BUILD_SENDER": "OctoKitty", "BUILD_STARTED": "1563474078", "BUILD_SOURCE": "https://github.com/github/octocat/48afb5bdc41ad69bf22588491333f7cf71135163", @@ -255,7 +253,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "VELA_BUILD_BASE_REF": "", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_BUILD_CHANNEL": "TODO", "VELA_BUILD_CLONE": "https://github.com/github/octocat.git", "VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -283,7 +281,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_AUTHOR": "OctoKitty", "BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "BUILD_BASE_REF": "", - "BUILD_BRANCH": "master", + "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", "BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -314,7 +312,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "VELA_BUILD_BASE_REF": "", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_BUILD_CHANNEL": "TODO", "VELA_BUILD_CLONE": "https://github.com/github/octocat.git", "VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -343,7 +341,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_AUTHOR": "OctoKitty", "BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "BUILD_BASE_REF": "", - "BUILD_BRANCH": "master", + "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", "BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -371,7 +369,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "VELA_BUILD_AUTHOR": "OctoKitty", "VELA_BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "VELA_BUILD_BASE_REF": "", - "VELA_BUILD_BRANCH": "master", + "VELA_BUILD_BRANCH": "main", "VELA_BUILD_CHANNEL": "TODO", "VELA_BUILD_CLONE": "https://github.com/github/octocat.git", "VELA_BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -397,7 +395,7 @@ func TestLibrary_Build_Environment(t *testing.T) { "BUILD_AUTHOR": "OctoKitty", "BUILD_AUTHOR_EMAIL": "OctoKitty@github.com", "BUILD_BASE_REF": "", - "BUILD_BRANCH": "master", + "BUILD_BRANCH": "main", "BUILD_CHANNEL": "TODO", "BUILD_CLONE": "https://github.com/github/octocat.git", "BUILD_COMMIT": "48afb5bdc41ad69bf22588491333f7cf71135163", @@ -860,8 +858,8 @@ func testBuild() *Build { b.SetAuthor("OctoKitty") b.SetEmail("OctoKitty@github.com") b.SetLink("https://example.company.com/github/octocat/1") - b.SetBranch("master") - b.SetRef("refs/heads/master") + b.SetBranch("main") + b.SetRef("refs/heads/main") b.SetBaseRef("") b.SetHeadRef("changes") b.SetHost("example.company.com") diff --git a/library/context.go b/library/context.go index e9925a84..f981bc63 100644 --- a/library/context.go +++ b/library/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/context_test.go b/library/context_test.go index 5a1f83ce..c3efdeff 100644 --- a/library/context_test.go +++ b/library/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/deployment.go b/library/deployment.go index 4879854c..a620a9e8 100644 --- a/library/deployment.go +++ b/library/deployment.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/deployment_test.go b/library/deployment_test.go index 62c5c4e6..03ce452e 100644 --- a/library/deployment_test.go +++ b/library/deployment_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -192,7 +190,7 @@ func testDeployment() *Deployment { d.SetURL("https://api.github.com/repos/github/octocat/deployments/1") d.SetUser("octocat") d.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") - d.SetRef("refs/heads/master") + d.SetRef("refs/heads/main") d.SetTask("vela-deploy") d.SetTarget("production") d.SetDescription("Deployment request from Vela") diff --git a/library/doc.go b/library/doc.go index 5b9a1761..06cc4475 100644 --- a/library/doc.go +++ b/library/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package library provides the defined library types for Vela. // diff --git a/library/executor.go b/library/executor.go index 33e43c1c..62200230 100644 --- a/library/executor.go +++ b/library/executor.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/executor_test.go b/library/executor_test.go index 929fb0ca..4955ae5e 100644 --- a/library/executor_test.go +++ b/library/executor_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/hook.go b/library/hook.go index 3f1e5070..f9d6b5e5 100644 --- a/library/hook.go +++ b/library/hook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/hook_test.go b/library/hook_test.go index e558b746..d0b6c0de 100644 --- a/library/hook_test.go +++ b/library/hook_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -239,7 +237,7 @@ func testHook() *Hook { h.SetHost("github.com") h.SetEvent("push") h.SetEventAction("") - h.SetBranch("master") + h.SetBranch("main") h.SetError("") h.SetStatus("success") h.SetLink("https://github.com/github/octocat/settings/hooks/1") diff --git a/library/log.go b/library/log.go index e38de1ed..cd7d39f9 100644 --- a/library/log.go +++ b/library/log.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -56,7 +54,8 @@ func (l *Log) MaskData(secrets []string) { // create regexp to match secrets in the log data surrounded by regexp metacharacters // // https://pkg.go.dev/regexp#MustCompile - re := regexp.MustCompile((`(\s|^|=|"|:|'|\.|,)` + escaped + `(\s|$|"|:|'|\.|,)`)) + buffer := `(\s|^|=|"|\?|:|'|\.|,|&|$|;)` + re := regexp.MustCompile((buffer + escaped + buffer)) // create a mask for the secret mask := fmt.Sprintf("$1%s$2", constants.SecretLogMask) diff --git a/library/log_test.go b/library/log_test.go index c25cf6f3..c3f796c8 100644 --- a/library/log_test.go +++ b/library/log_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -54,6 +52,8 @@ func TestLibrary_Log_MaskData(t *testing.T) { s3Masked := "$ echo $SECRET1\n***\n$ echo $SECRET2\n***\n" s4 := "SOME_SECRET=((%.YY245***pP.><@@}}" s4Masked := "SOME_SECRET=***" + s5 := "www.example.com?username=secret&password=extrasecret" + s5Masked := "www.example.com?username=***&password=***" tests := []struct { want []byte @@ -80,6 +80,11 @@ func TestLibrary_Log_MaskData(t *testing.T) { log: []byte(s4), secrets: sVals, }, + { // secret baked in URL query params + want: []byte(s5Masked), + log: []byte(s5), + secrets: sVals, + }, { // empty secrets slice want: []byte(s3), log: []byte(s3), diff --git a/library/pipeline.go b/library/pipeline.go index 16325d22..1a706604 100644 --- a/library/pipeline.go +++ b/library/pipeline.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/pipeline_test.go b/library/pipeline_test.go index b467e95c..ddc15aea 100644 --- a/library/pipeline_test.go +++ b/library/pipeline_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -245,7 +243,7 @@ func testPipeline() *Pipeline { p.SetCommit("48afb5bdc41ad69bf22588491333f7cf71135163") p.SetFlavor("large") p.SetPlatform("docker") - p.SetRef("refs/heads/master") + p.SetRef("refs/heads/main") p.SetRef("yaml") p.SetVersion("1") p.SetExternalSecrets(false) diff --git a/library/queue_info.go b/library/queue_info.go new file mode 100644 index 00000000..687c2c02 --- /dev/null +++ b/library/queue_info.go @@ -0,0 +1,63 @@ +// SPDX-License-Identifier: Apache-2.0 + +package library + +// QueueInfo is the library representation of a QueueInfo. +// +// swagger:model QueueInfo +type QueueInfo struct { + QueuePublicKey *string `json:"queue_public_key,omitempty"` + QueueAddress *string `json:"queue_address,omitempty"` +} + +// GetPublicKey returns the QueuePublicKey field. +// +// When the provided QueueInfo type is nil, or the field within +// the type is nil, it returns an empty string for the field. +func (w *QueueInfo) GetPublicKey() string { + // return zero value if QueueInfo type or QueuePublicKey field is nil + if w == nil || w.QueuePublicKey == nil { + return "" + } + + return *w.QueuePublicKey +} + +// GetQueueAddress returns the QueueAddress field. +// +// When the provided QueueInfo type is nil, or the field within +// the type is nil, it returns an empty string for the field. +func (w *QueueInfo) GetQueueAddress() string { + // return zero value if QueueInfo type or QueueAddress field is nil + if w == nil || w.QueueAddress == nil { + return "" + } + + return *w.QueueAddress +} + +// SetPublicKey sets the QueuePublicKey field. +// +// When the provided QueueInfo type is nil, it +// will set nothing and immediately return. +func (w *QueueInfo) SetPublicKey(v string) { + // return if QueueInfo type is nil + if w == nil { + return + } + + w.QueuePublicKey = &v +} + +// SetQueueAddress sets the QueueAddress field. +// +// When the provided QueueInfo type is nil, it +// will set nothing and immediately return. +func (w *QueueInfo) SetQueueAddress(v string) { + // return if QueueInfo type is nil + if w == nil { + return + } + + w.QueueAddress = &v +} diff --git a/library/queue_info_test.go b/library/queue_info_test.go new file mode 100644 index 00000000..f7375557 --- /dev/null +++ b/library/queue_info_test.go @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 + +package library + +import ( + "testing" +) + +func TestLibrary_QueueInfo_Getters(t *testing.T) { + // setup tests + tests := []struct { + qR *QueueInfo + want *QueueInfo + }{ + { + qR: testQueueInfo(), + want: testQueueInfo(), + }, + { + qR: new(QueueInfo), + want: new(QueueInfo), + }, + } + + // run tests + for _, test := range tests { + if test.qR.GetQueueAddress() != test.want.GetQueueAddress() { + t.Errorf("GetQueueAddress is %v, want %v", test.qR.GetQueueAddress(), test.want.GetQueueAddress()) + } + + if test.qR.GetPublicKey() != test.want.GetPublicKey() { + t.Errorf("GetPublicKey is %v, want %v", test.qR.GetPublicKey(), test.want.GetPublicKey()) + } + } +} + +func TestLibrary_QueueInfo_Setters(t *testing.T) { + // setup types + var w *QueueInfo + + // setup tests + tests := []struct { + qR *QueueInfo + want *QueueInfo + }{ + { + qR: testQueueInfo(), + want: testQueueInfo(), + }, + { + qR: w, + want: new(QueueInfo), + }, + } + + // run tests + for _, test := range tests { + test.qR.SetQueueAddress(test.want.GetQueueAddress()) + test.qR.SetPublicKey(test.want.GetPublicKey()) + + if test.qR.GetQueueAddress() != test.want.GetQueueAddress() { + t.Errorf("GetQueueAddress is %v, want %v", test.qR.GetQueueAddress(), test.want.GetQueueAddress()) + } + + if test.qR.GetPublicKey() != test.want.GetPublicKey() { + t.Errorf("GetPublicKey is %v, want %v", test.qR.GetPublicKey(), test.want.GetPublicKey()) + } + } +} + +// testQueueInfo is a test helper function to register a QueueInfo +// type with all fields set to a fake value. +func testQueueInfo() *QueueInfo { + w := new(QueueInfo) + w.SetQueueAddress("http://localhost:8080") + w.SetPublicKey("CuS+EQAzofbk3tVFS3bt5f2tIb4YiJJC4nVMFQYQElg=") + + return w +} diff --git a/library/repo.go b/library/repo.go index b12e9bc7..57a3b74e 100644 --- a/library/repo.go +++ b/library/repo.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/repo_test.go b/library/repo_test.go index f8e1f010..0dc48830 100644 --- a/library/repo_test.go +++ b/library/repo_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -19,7 +17,7 @@ func TestLibrary_Repo_Environment(t *testing.T) { "VELA_REPO_ALLOW_PULL": "false", "VELA_REPO_ALLOW_PUSH": "true", "VELA_REPO_ALLOW_TAG": "false", - "VELA_REPO_BRANCH": "master", + "VELA_REPO_BRANCH": "main", "VELA_REPO_TOPICS": "cloud,security", "VELA_REPO_BUILD_LIMIT": "10", "VELA_REPO_CLONE": "https://github.com/github/octocat.git", @@ -38,7 +36,7 @@ func TestLibrary_Repo_Environment(t *testing.T) { "REPOSITORY_ALLOW_PULL": "false", "REPOSITORY_ALLOW_PUSH": "true", "REPOSITORY_ALLOW_TAG": "false", - "REPOSITORY_BRANCH": "master", + "REPOSITORY_BRANCH": "main", "REPOSITORY_CLONE": "https://github.com/github/octocat.git", "REPOSITORY_FULL_NAME": "github/octocat", "REPOSITORY_LINK": "https://github.com/github/octocat", @@ -383,7 +381,7 @@ func testRepo() *Repo { r.SetFullName("github/octocat") r.SetLink("https://github.com/github/octocat") r.SetClone("https://github.com/github/octocat.git") - r.SetBranch("master") + r.SetBranch("main") r.SetTopics([]string{"cloud", "security"}) r.SetBuildLimit(10) r.SetTimeout(30) diff --git a/library/schedule.go b/library/schedule.go index 2f74c5f9..b9511e98 100644 --- a/library/schedule.go +++ b/library/schedule.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -22,6 +20,7 @@ type Schedule struct { UpdatedAt *int64 `json:"updated_at,omitempty"` UpdatedBy *string `json:"updated_by,omitempty"` ScheduledAt *int64 `json:"scheduled_at,omitempty"` + Branch *string `json:"branch,omitempty"` } // GetID returns the ID field from the provided Schedule. If the object is nil, @@ -134,6 +133,17 @@ func (s *Schedule) GetScheduledAt() int64 { return *s.ScheduledAt } +// GetBranch returns the Branch field from the provided Schedule. If the object is nil, +// or the field within the object is nil, it returns the zero value instead. +func (s *Schedule) GetBranch() string { + // return zero value if Schedule type or ScheduledAt field is nil + if s == nil || s.Branch == nil { + return "" + } + + return *s.Branch +} + // SetID sets the ID field in the provided Schedule. If the object is nil, // it will set nothing and immediately return making this a no-op. func (s *Schedule) SetID(id int64) { @@ -244,6 +254,17 @@ func (s *Schedule) SetScheduledAt(scheduledAt int64) { s.ScheduledAt = &scheduledAt } +// SetBranch sets the Branch field in the provided Schedule. If the object is nil, +// it will set nothing and immediately return making this a no-op. +func (s *Schedule) SetBranch(branch string) { + // return if Schedule type is nil + if s == nil { + return + } + + s.Branch = &branch +} + // String implements the Stringer interface for the Schedule type. func (s *Schedule) String() string { return fmt.Sprintf(`{ @@ -257,6 +278,7 @@ func (s *Schedule) String() string { ScheduledAt: %d, UpdatedAt: %d, UpdatedBy: %s, + Branch: %s, }`, s.GetActive(), s.GetCreatedAt(), @@ -268,5 +290,6 @@ func (s *Schedule) String() string { s.GetScheduledAt(), s.GetUpdatedAt(), s.GetUpdatedBy(), + s.GetBranch(), ) } diff --git a/library/schedule_test.go b/library/schedule_test.go index 9cf75313..b2f8db54 100644 --- a/library/schedule_test.go +++ b/library/schedule_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -66,6 +64,9 @@ func TestLibrary_Schedule_Getters(t *testing.T) { if test.schedule.GetScheduledAt() != test.want.GetScheduledAt() { t.Errorf("GetScheduledAt is %v, want %v", test.schedule.GetScheduledAt(), test.want.GetScheduledAt()) } + if test.schedule.GetBranch() != test.want.GetBranch() { + t.Errorf("GetBranch is %v, want %v", test.schedule.GetBranch(), test.want.GetBranch()) + } }) } } @@ -136,6 +137,10 @@ func TestLibrary_Schedule_Setters(t *testing.T) { if test.schedule.GetScheduledAt() != test.want.GetScheduledAt() { t.Errorf("SetScheduledAt is %v, want %v", test.schedule.GetScheduledAt(), test.want.GetScheduledAt()) } + test.schedule.SetBranch(test.want.GetBranch()) + if test.schedule.GetBranch() != test.want.GetBranch() { + t.Errorf("SetBranch is %v, want %v", test.schedule.GetBranch(), test.want.GetBranch()) + } }) } } @@ -154,6 +159,7 @@ func TestLibrary_Schedule_String(t *testing.T) { ScheduledAt: %d, UpdatedAt: %d, UpdatedBy: %s, + Branch: %s, }`, s.GetActive(), s.GetCreatedAt(), @@ -165,6 +171,7 @@ func TestLibrary_Schedule_String(t *testing.T) { s.GetScheduledAt(), s.GetUpdatedAt(), s.GetUpdatedBy(), + s.GetBranch(), ) got := s.String() @@ -186,6 +193,7 @@ func testSchedule() *Schedule { s.SetUpdatedAt(time.Now().Add(time.Hour * 1).UTC().Unix()) s.SetUpdatedBy("user2") s.SetScheduledAt(time.Now().Add(time.Hour * 2).UTC().Unix()) + s.SetBranch("main") return s } diff --git a/library/secret.go b/library/secret.go index e4d498f3..62dd5e43 100644 --- a/library/secret.go +++ b/library/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -70,7 +68,7 @@ func (s *Secret) Match(from *pipeline.Container) bool { } // check incoming events - switch from.Environment["BUILD_EVENT"] { + switch from.Environment["VELA_BUILD_EVENT"] { case constants.EventPush: eACL = checkEvent(events, constants.EventPush) case constants.EventPull: @@ -81,6 +79,8 @@ func (s *Secret) Match(from *pipeline.Container) bool { eACL = checkEvent(events, constants.EventDeploy) case constants.EventComment: eACL = checkEvent(events, constants.EventComment) + case constants.EventSchedule: + eACL = checkEvent(events, constants.EventSchedule) } // check images whitelist diff --git a/library/secret_test.go b/library/secret_test.go index c97b18a9..4fe2986f 100644 --- a/library/secret_test.go +++ b/library/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library @@ -43,7 +41,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { // test matching secret events step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"push"}}, want: true, @@ -51,7 +49,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "pull_request"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"pull_request"}}, want: true, @@ -59,7 +57,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "tag"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "tag"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"tag"}}, want: true, @@ -67,7 +65,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "deployment"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "deployment"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"deployment"}}, want: true, @@ -75,7 +73,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "comment"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "comment"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"comment"}}, want: true, @@ -83,7 +81,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "fake_event"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "fake_event"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"push"}}, want: false, @@ -91,16 +89,24 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"push", "pull_request"}}, want: true, }, + { + step: &pipeline.Container{ + Image: "alpine:latest", + Environment: map[string]string{"VELA_BUILD_EVENT": "schedule"}, + }, + sec: &Secret{Name: &v, Value: &v, Images: &[]string{}, Events: &[]string{"push", "pull_request", "schedule"}}, + want: true, + }, { // test matching secret images step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine"}, Events: &[]string{}}, want: true, @@ -108,7 +114,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{}}, want: true, @@ -116,7 +122,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:1"}, Events: &[]string{}}, want: false, @@ -124,7 +130,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine", "centos"}, Events: &[]string{}}, want: true, @@ -133,7 +139,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { // test matching secret events and images step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine"}, Events: &[]string{"push"}}, want: true, @@ -141,7 +147,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{"push"}}, want: true, @@ -149,7 +155,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:1"}, Events: &[]string{"push"}}, want: false, @@ -157,7 +163,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "pull_request"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "pull_request"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine:latest"}, Events: &[]string{"push"}}, want: false, @@ -165,7 +171,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, }, sec: &Secret{Name: &v, Value: &v, Images: &[]string{"alpine", "centos"}, Events: &[]string{"push"}}, want: true, @@ -174,7 +180,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { // test build events with image ACLs and rulesets step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, Ruleset: pipeline.Ruleset{ If: pipeline.Rules{ Event: []string{"push"}, @@ -187,7 +193,7 @@ func TestLibrary_Secret_Match(t *testing.T) { { step: &pipeline.Container{ Image: "alpine:latest", - Environment: map[string]string{"BUILD_EVENT": "push"}, + Environment: map[string]string{"VELA_BUILD_EVENT": "push"}, Ruleset: pipeline.Ruleset{ If: pipeline.Rules{ Event: []string{"push"}, diff --git a/library/service.go b/library/service.go index 97d9b193..b5ed543b 100644 --- a/library/service.go +++ b/library/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/service_test.go b/library/service_test.go index dbc9ee57..9af18490 100644 --- a/library/service_test.go +++ b/library/service_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/step.go b/library/step.go index d35ab3e8..5dfa8aee 100644 --- a/library/step.go +++ b/library/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/step_test.go b/library/step_test.go index 5df44029..60446d4e 100644 --- a/library/step_test.go +++ b/library/step_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/string.go b/library/string.go index 0e92d2d3..79dac91d 100644 --- a/library/string.go +++ b/library/string.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/string_test.go b/library/string_test.go index faa83352..7447674b 100644 --- a/library/string_test.go +++ b/library/string_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/template.go b/library/template.go index 79bc8d36..6a4e58cb 100644 --- a/library/template.go +++ b/library/template.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 //nolint:dupl // ignore false positive with build_queue.go package library diff --git a/library/template_test.go b/library/template_test.go index 5c723abd..4ea3cc4a 100644 --- a/library/template_test.go +++ b/library/template_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/token.go b/library/token.go index e6f93bfc..06f626b2 100644 --- a/library/token.go +++ b/library/token.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/token_test.go b/library/token_test.go index d0375a95..7950c7fd 100644 --- a/library/token_test.go +++ b/library/token_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/user.go b/library/user.go index 34b25b2e..3e2deb8e 100644 --- a/library/user.go +++ b/library/user.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/user_test.go b/library/user_test.go index d613c40e..76657373 100644 --- a/library/user_test.go +++ b/library/user_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/worker.go b/library/worker.go index a11075c9..a454190a 100644 --- a/library/worker.go +++ b/library/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/library/worker_test.go b/library/worker_test.go index 580cc73d..0bc68e43 100644 --- a/library/worker_test.go +++ b/library/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package library diff --git a/metadata.go b/metadata.go index f0b81152..1c9acf2f 100644 --- a/metadata.go +++ b/metadata.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types diff --git a/pipeline/build.go b/pipeline/build.go index 61fc127e..1bd5d122 100644 --- a/pipeline/build.go +++ b/pipeline/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/build_test.go b/pipeline/build_test.go index a6e5d2e6..b43418fa 100644 --- a/pipeline/build_test.go +++ b/pipeline/build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -73,11 +71,11 @@ func TestPipeline_Build_Purge(t *testing.T) { // run tests for _, test := range tests { r := &RuleData{ - Branch: "master", + Branch: "main", Event: "pull_request", Path: []string{}, Repo: "foo/bar", - Tag: "refs/heads/master", + Tag: "refs/heads/main", } got := test.pipeline.Purge(r) diff --git a/pipeline/container.go b/pipeline/container.go index d10849c3..82867548 100644 --- a/pipeline/container.go +++ b/pipeline/container.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/container_test.go b/pipeline/container_test.go index fe474fbe..9c94e2fc 100644 --- a/pipeline/container_test.go +++ b/pipeline/container_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -34,11 +32,11 @@ func TestPipeline_ContainerSlice_Purge(t *testing.T) { // run tests for _, test := range tests { r := &RuleData{ - Branch: "master", + Branch: "main", Event: "pull_request", Path: []string{}, Repo: "foo/bar", - Tag: "refs/heads/master", + Tag: "refs/heads/main", } got := test.containers.Purge(r) @@ -157,7 +155,7 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -172,7 +170,7 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -187,7 +185,7 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -207,7 +205,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -227,7 +225,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -246,7 +244,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -265,7 +263,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -284,7 +282,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -303,7 +301,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -317,13 +315,13 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -337,13 +335,13 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -357,14 +355,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Path: []string{"README.md"}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -378,14 +376,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Path: []string{"README.md"}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -399,14 +397,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Path: []string{"README.md"}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -483,14 +481,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Status: []string{constants.StatusSuccess}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -504,14 +502,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Status: []string{constants.StatusSuccess}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -525,14 +523,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Status: []string{constants.StatusSuccess}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -546,7 +544,7 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Status: []string{constants.StatusSuccess}, }, @@ -554,7 +552,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -575,7 +573,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "tag", Repo: "foo/bar", Status: "running", @@ -597,7 +595,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "tag", Repo: "foo/bar", Status: "success", @@ -619,7 +617,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "tag", Repo: "foo/bar", Status: "failure", @@ -639,7 +637,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "running", @@ -658,7 +656,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -677,7 +675,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "failure", @@ -691,14 +689,14 @@ func TestPipeline_Container_Execute(t *testing.T) { Commands: []string{"echo \"Hey Vela\""}, Ruleset: Ruleset{ Unless: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{constants.EventPush}, Status: []string{constants.StatusSuccess}, }, }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Repo: "foo/bar", Status: "success", @@ -719,7 +717,7 @@ func TestPipeline_Container_Execute(t *testing.T) { }, }, ruleData: &RuleData{ - Branch: "master", + Branch: "main", Event: "pull_request", Repo: "foo/bar", Status: "failure", diff --git a/pipeline/context.go b/pipeline/context.go index 35d82148..7eae49b1 100644 --- a/pipeline/context.go +++ b/pipeline/context.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/context_test.go b/pipeline/context_test.go index ee126446..899c7b92 100644 --- a/pipeline/context_test.go +++ b/pipeline/context_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/doc.go b/pipeline/doc.go index 707ade9b..ccce0822 100644 --- a/pipeline/doc.go +++ b/pipeline/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package pipeline provides the defined pipeline types for Vela. // diff --git a/pipeline/metadata.go b/pipeline/metadata.go index cee1d4c1..c4f5fdf8 100644 --- a/pipeline/metadata.go +++ b/pipeline/metadata.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/port.go b/pipeline/port.go index 80163fe6..6ce572b5 100644 --- a/pipeline/port.go +++ b/pipeline/port.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/ruleset.go b/pipeline/ruleset.go index 4d8f4b4b..d1b6c5b3 100644 --- a/pipeline/ruleset.go +++ b/pipeline/ruleset.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/ruleset_test.go b/pipeline/ruleset_test.go index 64ad3679..fb97a696 100644 --- a/pipeline/ruleset_test.go +++ b/pipeline/ruleset_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -16,144 +14,144 @@ func TestPipeline_Ruleset_Match(t *testing.T) { want bool }{ // Empty - {ruleset: &Ruleset{}, data: &RuleData{Branch: "master"}, want: true}, + {ruleset: &Ruleset{}, data: &RuleData{Branch: "main"}, want: true}, // If with and operator { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}}}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}}}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}}}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}, Event: []string{"push"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}, Event: []string{"push"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { ruleset: &Ruleset{If: Rules{Path: []string{"foo.txt", "/foo/bar.txt"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { ruleset: &Ruleset{If: Rules{Comment: []string{"rerun"}}}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { ruleset: &Ruleset{If: Rules{Comment: []string{"rerun"}}}, - data: &RuleData{Branch: "dev", Comment: "ok to test", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "dev", Comment: "ok to test", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { ruleset: &Ruleset{If: Rules{Event: []string{"deployment"}, Target: []string{"production"}}}, - data: &RuleData{Branch: "dev", Comment: "", Event: "deployment", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: "production"}, + data: &RuleData{Branch: "dev", Comment: "", Event: "deployment", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: "production"}, want: true, }, { ruleset: &Ruleset{If: Rules{Event: []string{"deployment"}, Target: []string{"production"}}}, - data: &RuleData{Branch: "dev", Comment: "", Event: "deployment", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: "stage"}, + data: &RuleData{Branch: "dev", Comment: "", Event: "deployment", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: "stage"}, want: false, }, { ruleset: &Ruleset{If: Rules{Event: []string{"schedule"}, Target: []string{"weekly"}}}, - data: &RuleData{Branch: "dev", Comment: "", Event: "schedule", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: "weekly"}, + data: &RuleData{Branch: "dev", Comment: "", Event: "schedule", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: "weekly"}, want: true, }, { ruleset: &Ruleset{If: Rules{Event: []string{"schedule"}, Target: []string{"weekly"}}}, - data: &RuleData{Branch: "dev", Comment: "", Event: "schedule", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: "nightly"}, + data: &RuleData{Branch: "dev", Comment: "", Event: "schedule", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: "nightly"}, want: false, }, { ruleset: &Ruleset{If: Rules{Status: []string{"success", "failure"}}}, - data: &RuleData{Branch: "dev", Comment: "ok to test", Event: "push", Repo: "octocat/hello-world", Status: "failure", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "dev", Comment: "ok to test", Event: "push", Repo: "octocat/hello-world", Status: "failure", Tag: "refs/heads/main", Target: ""}, want: true, }, // If with or operator { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { - ruleset: &Ruleset{If: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{If: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { ruleset: &Ruleset{If: Rules{Path: []string{"foo.txt", "/foo/bar.txt"}}, Operator: "or"}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, // Unless with and operator { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}}}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}}}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}}}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}, Event: []string{"push"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}, Event: []string{"push"}}}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}, Event: []string{"push"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}, Event: []string{"push"}}}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { ruleset: &Ruleset{Unless: Rules{Path: []string{"foo.txt", "/foo/bar.txt"}}}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, // Unless with or operator { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, { - ruleset: &Ruleset{Unless: Rules{Branch: []string{"master"}, Event: []string{"push"}}, Operator: "or"}, - data: &RuleData{Branch: "dev", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + ruleset: &Ruleset{Unless: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Operator: "or"}, + data: &RuleData{Branch: "dev", Comment: "rerun", Event: "pull_request", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, { ruleset: &Ruleset{Unless: Rules{Path: []string{"foo.txt", "/foo/bar.txt"}}, Operator: "or"}, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "pull_request", Path: []string{}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: true, }, // Advanced Rulesets @@ -165,7 +163,7 @@ func TestPipeline_Ruleset_Match(t *testing.T) { }, Operator: "or", }, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, want: true, }, { @@ -176,7 +174,7 @@ func TestPipeline_Ruleset_Match(t *testing.T) { }, Operator: "or", }, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, want: true, }, { @@ -187,7 +185,7 @@ func TestPipeline_Ruleset_Match(t *testing.T) { }, Operator: "or", }, - data: &RuleData{Branch: "master", Comment: "rerun", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Comment: "rerun", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, want: false, }, } @@ -228,7 +226,7 @@ func TestPipeline_Rules_Empty(t *testing.T) { func TestPipeline_Rules_Empty_Invalid(t *testing.T) { // setup types - r := Rules{Branch: []string{"master"}} + r := Rules{Branch: []string{"main"}} // run test got := r.Empty() @@ -248,37 +246,37 @@ func TestPipeline_Rules_Match_Regex_Tag(t *testing.T) { }{ { rules: &Rules{Event: []string{"tag"}, Tag: []string{"refs/tags/20.*"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"[0-9][0-9].[0-9].[0-9][0-9].[0-9][0-9][0-9]"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"^refs/tags/(\\d+\\.)+\\d+$"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/20.4.42.167", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"^refs/tags/(\\d+\\.)+\\d+"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/2.4.42.165-prod", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/2.4.42.165-prod", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"^refs/tags/(\\d+\\.)+\\d+$"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/2.4.42.165-prod", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/2.4.42.165-prod", Target: ""}, operator: "and", want: false, }, @@ -305,112 +303,112 @@ func TestPipeline_Rules_Match(t *testing.T) { // Empty { rules: &Rules{}, - data: &RuleData{Branch: "master", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "and", want: true, }, { rules: &Rules{}, - data: &RuleData{Branch: "master", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: false, }, // and operator { - rules: &Rules{Branch: []string{"master"}}, - data: &RuleData{Branch: "master", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}}, + data: &RuleData{Branch: "main", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "and", want: true, }, { - rules: &Rules{Branch: []string{"master"}}, - data: &RuleData{Branch: "dev", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}}, + data: &RuleData{Branch: "dev", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "and", want: false, }, { - rules: &Rules{Branch: []string{"master"}, Event: []string{"push"}}, - data: &RuleData{Branch: "master", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}, Event: []string{"push"}}, + data: &RuleData{Branch: "main", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "and", want: true, }, { - rules: &Rules{Branch: []string{"master"}, Event: []string{"push"}}, - data: &RuleData{Branch: "master", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}, Event: []string{"push"}}, + data: &RuleData{Branch: "main", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "and", want: false, }, { rules: &Rules{Path: []string{"foob.txt"}}, - data: &RuleData{Branch: "master", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "and", want: false, }, { rules: &Rules{Status: []string{"success", "failure"}}, - data: &RuleData{Branch: "master", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Tag: "refs/heads/main", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"refs/tags/[0-9].*-prod"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/2.4.42.167-prod", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/tags/2.4.42.167-prod", Target: ""}, operator: "and", want: true, }, { rules: &Rules{Event: []string{"tag"}, Tag: []string{"path/to/thing/*/*"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "path/to/thing/stage/1.0.2-rc", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "path/to/thing/stage/1.0.2-rc", Target: ""}, operator: "and", want: true, }, // or operator { - rules: &Rules{Branch: []string{"master"}, Event: []string{"push"}}, - data: &RuleData{Branch: "master", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}, Event: []string{"push"}}, + data: &RuleData{Branch: "main", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: true, }, { - rules: &Rules{Branch: []string{"master"}, Event: []string{"push"}}, - data: &RuleData{Branch: "dev", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}, Event: []string{"push"}}, + data: &RuleData{Branch: "dev", Event: "push", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: true, }, { - rules: &Rules{Branch: []string{"master"}, Event: []string{"push"}}, - data: &RuleData{Branch: "master", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}, Event: []string{"push"}}, + data: &RuleData{Branch: "main", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: true, }, { - rules: &Rules{Branch: []string{"master"}, Event: []string{"push"}}, - data: &RuleData{Branch: "dev", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + rules: &Rules{Branch: []string{"main"}, Event: []string{"push"}}, + data: &RuleData{Branch: "dev", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: false, }, { rules: &Rules{Path: []string{"foob.txt"}}, - data: &RuleData{Branch: "dev", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "dev", Event: "pull_request", Path: []string{"foo.txt", "/foo/bar.txt"}, Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: false, }, // Advanced Rulesets { rules: &Rules{Event: []string{"push", "pull_request"}, Tag: []string{"release/*"}}, - data: &RuleData{Branch: "master", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, + data: &RuleData{Branch: "main", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, operator: "or", want: true, }, { rules: &Rules{Event: []string{"push", "pull_request"}, Tag: []string{"release/*"}}, - data: &RuleData{Branch: "master", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, + data: &RuleData{Branch: "main", Event: "push", Repo: "octocat/hello-world", Status: "pending", Tag: "release/*", Target: ""}, operator: "or", want: true, }, { rules: &Rules{Event: []string{"push", "pull_request"}, Tag: []string{"release/*"}}, - data: &RuleData{Branch: "master", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/master", Target: ""}, + data: &RuleData{Branch: "main", Event: "tag", Repo: "octocat/hello-world", Status: "pending", Tag: "refs/heads/main", Target: ""}, operator: "or", want: false, }, @@ -435,14 +433,14 @@ func TestPipeline_Ruletype_MatchAnd(t *testing.T) { want bool }{ // Empty with filepath matcher - {matcher: "filepath", rule: []string{}, pattern: "master", want: true}, + {matcher: "filepath", rule: []string{}, pattern: "main", want: true}, {matcher: "filepath", rule: []string{}, pattern: "push", want: true}, {matcher: "filepath", rule: []string{}, pattern: "foo/bar", want: true}, {matcher: "filepath", rule: []string{}, pattern: "success", want: true}, {matcher: "filepath", rule: []string{}, pattern: "release/*", want: true}, // Branch with filepath matcher - {matcher: "filepath", rule: []string{"master"}, pattern: "master", want: true}, - {matcher: "filepath", rule: []string{"master"}, pattern: "dev", want: false}, + {matcher: "filepath", rule: []string{"main"}, pattern: "main", want: true}, + {matcher: "filepath", rule: []string{"main"}, pattern: "dev", want: false}, // Comment with filepath matcher {matcher: "filepath", rule: []string{"ok to test"}, pattern: "ok to test", want: true}, {matcher: "filepath", rule: []string{"ok to test"}, pattern: "rerun", want: false}, @@ -470,14 +468,14 @@ func TestPipeline_Ruletype_MatchAnd(t *testing.T) { {matcher: "filepath", rule: []string{"production"}, pattern: "production", want: true}, {matcher: "filepath", rule: []string{"stage"}, pattern: "production", want: false}, // Empty with regex matcher - {matcher: "regexp", rule: []string{}, pattern: "master", want: true}, + {matcher: "regexp", rule: []string{}, pattern: "main", want: true}, {matcher: "regexp", rule: []string{}, pattern: "push", want: true}, {matcher: "regexp", rule: []string{}, pattern: "foo/bar", want: true}, {matcher: "regexp", rule: []string{}, pattern: "success", want: true}, {matcher: "regexp", rule: []string{}, pattern: "release/*", want: true}, // Branch with regex matcher - {matcher: "regexp", rule: []string{"master"}, pattern: "master", want: true}, - {matcher: "regexp", rule: []string{"master"}, pattern: "dev", want: false}, + {matcher: "regexp", rule: []string{"main"}, pattern: "main", want: true}, + {matcher: "regexp", rule: []string{"main"}, pattern: "dev", want: false}, // Comment with regex matcher {matcher: "regexp", rule: []string{"ok to test"}, pattern: "ok to test", want: true}, {matcher: "regexp", rule: []string{"ok to test"}, pattern: "rerun", want: false}, @@ -525,14 +523,14 @@ func TestPipeline_Ruletype_MatchOr(t *testing.T) { want bool }{ // Empty with filepath matcher - {matcher: "filepath", rule: []string{}, pattern: "master", want: false}, + {matcher: "filepath", rule: []string{}, pattern: "main", want: false}, {matcher: "filepath", rule: []string{}, pattern: "push", want: false}, {matcher: "filepath", rule: []string{}, pattern: "foo/bar", want: false}, {matcher: "filepath", rule: []string{}, pattern: "success", want: false}, {matcher: "filepath", rule: []string{}, pattern: "release/*", want: false}, // Branch with filepath matcher - {matcher: "filepath", rule: []string{"master"}, pattern: "master", want: true}, - {matcher: "filepath", rule: []string{"master"}, pattern: "dev", want: false}, + {matcher: "filepath", rule: []string{"main"}, pattern: "main", want: true}, + {matcher: "filepath", rule: []string{"main"}, pattern: "dev", want: false}, // Comment with filepath matcher {matcher: "filepath", rule: []string{"ok to test"}, pattern: "ok to test", want: true}, {matcher: "filepath", rule: []string{"ok to test"}, pattern: "rerun", want: false}, @@ -552,14 +550,14 @@ func TestPipeline_Ruletype_MatchOr(t *testing.T) { {matcher: "filepath", rule: []string{"production"}, pattern: "production", want: true}, {matcher: "filepath", rule: []string{"stage"}, pattern: "production", want: false}, // Empty with regexp matcher - {matcher: "regexp", rule: []string{}, pattern: "master", want: false}, + {matcher: "regexp", rule: []string{}, pattern: "main", want: false}, {matcher: "regexp", rule: []string{}, pattern: "push", want: false}, {matcher: "regexp", rule: []string{}, pattern: "foo/bar", want: false}, {matcher: "regexp", rule: []string{}, pattern: "success", want: false}, {matcher: "regexp", rule: []string{}, pattern: "release/*", want: false}, // Branch with regexp matcher - {matcher: "regexp", rule: []string{"master"}, pattern: "master", want: true}, - {matcher: "regexp", rule: []string{"master"}, pattern: "dev", want: false}, + {matcher: "regexp", rule: []string{"main"}, pattern: "main", want: true}, + {matcher: "regexp", rule: []string{"main"}, pattern: "dev", want: false}, // Comment with regexp matcher {matcher: "regexp", rule: []string{"ok to test"}, pattern: "ok to test", want: true}, {matcher: "regexp", rule: []string{"ok to test"}, pattern: "rerun", want: false}, diff --git a/pipeline/secret.go b/pipeline/secret.go index 6f1f6f0d..6e51f941 100644 --- a/pipeline/secret.go +++ b/pipeline/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/secret_test.go b/pipeline/secret_test.go index febd2767..a4ff7a10 100644 --- a/pipeline/secret_test.go +++ b/pipeline/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -34,11 +32,11 @@ func TestPipeline_SecretSlice_Purge(t *testing.T) { // run tests for _, test := range tests { r := &RuleData{ - Branch: "master", + Branch: "main", Event: "push", Path: []string{}, Repo: "foo/bar", - Tag: "refs/heads/master", + Tag: "refs/heads/main", } got := test.secrets.Purge(r) diff --git a/pipeline/stage.go b/pipeline/stage.go index e1c9d449..29966677 100644 --- a/pipeline/stage.go +++ b/pipeline/stage.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/stage_test.go b/pipeline/stage_test.go index c21e7ad3..919803dc 100644 --- a/pipeline/stage_test.go +++ b/pipeline/stage_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline @@ -34,11 +32,11 @@ func TestPipeline_StageSlice_Purge(t *testing.T) { // run tests for _, test := range tests { r := &RuleData{ - Branch: "master", + Branch: "main", Event: "pull_request", Path: []string{}, Repo: "foo/bar", - Tag: "refs/heads/master", + Tag: "refs/heads/main", } got := test.stages.Purge(r) diff --git a/pipeline/ulimit.go b/pipeline/ulimit.go index fac7c355..a32b6c90 100644 --- a/pipeline/ulimit.go +++ b/pipeline/ulimit.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/volume.go b/pipeline/volume.go index 91cd5200..c99342f5 100644 --- a/pipeline/volume.go +++ b/pipeline/volume.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/worker.go b/pipeline/worker.go index 765c3d73..1c667bfc 100644 --- a/pipeline/worker.go +++ b/pipeline/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/pipeline/worker_test.go b/pipeline/worker_test.go index 6ddf4e95..a026d4aa 100644 --- a/pipeline/worker_test.go +++ b/pipeline/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package pipeline diff --git a/raw/doc.go b/raw/doc.go index 56e1d2da..7321b7f3 100644 --- a/raw/doc.go +++ b/raw/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package raw provides the defined raw types for Vela. // diff --git a/raw/map.go b/raw/map.go index 1e134cb8..ed8fff42 100644 --- a/raw/map.go +++ b/raw/map.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package raw diff --git a/raw/map_test.go b/raw/map_test.go index a53728cd..aec603f4 100644 --- a/raw/map_test.go +++ b/raw/map_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package raw diff --git a/raw/slice.go b/raw/slice.go index f07565ef..11746363 100644 --- a/raw/slice.go +++ b/raw/slice.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package raw diff --git a/raw/slice_test.go b/raw/slice_test.go index 96156ea8..7a32bd3d 100644 --- a/raw/slice_test.go +++ b/raw/slice_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package raw diff --git a/version/doc.go b/version/doc.go index ed85332e..603a2379 100644 --- a/version/doc.go +++ b/version/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package version provides the defined version types for Vela. // diff --git a/version/metadata.go b/version/metadata.go index 9e8a9a8d..3cb7fcfb 100644 --- a/version/metadata.go +++ b/version/metadata.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package version diff --git a/version/metadata_test.go b/version/metadata_test.go index e2ce617f..831e2c32 100644 --- a/version/metadata_test.go +++ b/version/metadata_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package version diff --git a/version/version.go b/version/version.go index d9522fac..148f9499 100644 --- a/version/version.go +++ b/version/version.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package version diff --git a/version/version_test.go b/version/version_test.go index 48b58982..620ad526 100644 --- a/version/version_test.go +++ b/version/version_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package version diff --git a/webhook.go b/webhook.go index 32398ae9..838adca9 100644 --- a/webhook.go +++ b/webhook.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types diff --git a/webhook_test.go b/webhook_test.go index 6a04e133..061ad8a4 100644 --- a/webhook_test.go +++ b/webhook_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package types diff --git a/yaml/build.go b/yaml/build.go index 5c2719e0..4c28986f 100644 --- a/yaml/build.go +++ b/yaml/build.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/build_test.go b/yaml/build_test.go index adb9ed63..4b652e98 100644 --- a/yaml/build_test.go +++ b/yaml/build_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml @@ -240,7 +238,7 @@ func TestYaml_Build_UnmarshalYAML(t *testing.T) { Image: "plugins/docker:18.09", Pull: "always", Ruleset: Ruleset{ - If: Rules{Branch: []string{"master"}, Event: []string{"push"}}, + If: Rules{Branch: []string{"main"}, Event: []string{"push"}}, Matcher: "filepath", Operator: "and", }, diff --git a/yaml/doc.go b/yaml/doc.go index ffe11f1f..88753d51 100644 --- a/yaml/doc.go +++ b/yaml/doc.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 // Package yaml provides the defined yaml types for Vela. // diff --git a/yaml/metadata.go b/yaml/metadata.go index 08fa7a0a..e73d6937 100644 --- a/yaml/metadata.go +++ b/yaml/metadata.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/metadata_test.go b/yaml/metadata_test.go index 901155bb..5bedfe23 100644 --- a/yaml/metadata_test.go +++ b/yaml/metadata_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/ruleset.go b/yaml/ruleset.go index 664cdd4b..0d29b0b1 100644 --- a/yaml/ruleset.go +++ b/yaml/ruleset.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/ruleset_test.go b/yaml/ruleset_test.go index 6f0363bc..31ce53a0 100644 --- a/yaml/ruleset_test.go +++ b/yaml/ruleset_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2023 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml @@ -22,7 +20,7 @@ func TestYaml_Ruleset_ToPipeline(t *testing.T) { { ruleset: &Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -32,7 +30,7 @@ func TestYaml_Ruleset_ToPipeline(t *testing.T) { Target: []string{"production"}, }, Unless: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"real comment"}, Event: []string{"pull_request"}, Path: []string{"bar.txt"}, @@ -47,7 +45,7 @@ func TestYaml_Ruleset_ToPipeline(t *testing.T) { }, want: &pipeline.Ruleset{ If: pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -57,7 +55,7 @@ func TestYaml_Ruleset_ToPipeline(t *testing.T) { Target: []string{"production"}, }, Unless: pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"real comment"}, Event: []string{"pull_request"}, Path: []string{"bar.txt"}, @@ -93,7 +91,7 @@ func TestYaml_Ruleset_UnmarshalYAML(t *testing.T) { file: "testdata/ruleset_simple.yml", want: &Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -111,7 +109,7 @@ func TestYaml_Ruleset_UnmarshalYAML(t *testing.T) { file: "testdata/ruleset_advanced.yml", want: &Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{"push"}, Tag: []string{"^refs/tags/(\\d+\\.)+\\d+$"}, }, @@ -128,7 +126,7 @@ func TestYaml_Ruleset_UnmarshalYAML(t *testing.T) { file: "testdata/ruleset_regex.yml", want: &Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Event: []string{"tag"}, Tag: []string{"^refs/tags/(\\d+\\.)+\\d+$"}, }, @@ -167,7 +165,7 @@ func TestYaml_Rules_ToPipeline(t *testing.T) { }{ { rules: &Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -177,7 +175,7 @@ func TestYaml_Rules_ToPipeline(t *testing.T) { Target: []string{"production"}, }, want: &pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -216,7 +214,7 @@ func TestYaml_Rules_UnmarshalYAML(t *testing.T) { failure: false, file: "testdata/ruleset_simple.yml", want: &Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, diff --git a/yaml/secret.go b/yaml/secret.go index 453341cf..a211a245 100644 --- a/yaml/secret.go +++ b/yaml/secret.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/secret_test.go b/yaml/secret_test.go index 2c238f02..9cb4dae6 100644 --- a/yaml/secret_test.go +++ b/yaml/secret_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/service.go b/yaml/service.go index bd2ba468..4fa41277 100644 --- a/yaml/service.go +++ b/yaml/service.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/service_test.go b/yaml/service_test.go index a422f02e..d0404eef 100644 --- a/yaml/service_test.go +++ b/yaml/service_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/stage.go b/yaml/stage.go index 8a4bc5d6..bfc0dffb 100644 --- a/yaml/stage.go +++ b/yaml/stage.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/stage_test.go b/yaml/stage_test.go index 88c23a29..cf90ba48 100644 --- a/yaml/stage_test.go +++ b/yaml/stage_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml @@ -37,7 +35,7 @@ func TestYaml_StageSlice_ToPipeline(t *testing.T) { Pull: "not_present", Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -47,7 +45,7 @@ func TestYaml_StageSlice_ToPipeline(t *testing.T) { Target: []string{"production"}, }, Unless: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"real comment"}, Event: []string{"pull_request"}, Path: []string{"bar.txt"}, @@ -99,7 +97,7 @@ func TestYaml_StageSlice_ToPipeline(t *testing.T) { Pull: "not_present", Ruleset: pipeline.Ruleset{ If: pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -109,7 +107,7 @@ func TestYaml_StageSlice_ToPipeline(t *testing.T) { Target: []string{"production"}, }, Unless: pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"real comment"}, Event: []string{"pull_request"}, Path: []string{"bar.txt"}, diff --git a/yaml/step.go b/yaml/step.go index da7ad43e..82232143 100644 --- a/yaml/step.go +++ b/yaml/step.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/step_test.go b/yaml/step_test.go index 5fb82323..e1cead4c 100644 --- a/yaml/step_test.go +++ b/yaml/step_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml @@ -34,7 +32,7 @@ func TestYaml_StepSlice_ToPipeline(t *testing.T) { Pull: "not_present", Ruleset: Ruleset{ If: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -44,7 +42,7 @@ func TestYaml_StepSlice_ToPipeline(t *testing.T) { Target: []string{"production"}, }, Unless: Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"real comment"}, Event: []string{"pull_request"}, Path: []string{"bar.txt"}, @@ -90,7 +88,7 @@ func TestYaml_StepSlice_ToPipeline(t *testing.T) { Pull: "not_present", Ruleset: pipeline.Ruleset{ If: pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"test comment"}, Event: []string{"push"}, Path: []string{"foo.txt"}, @@ -100,7 +98,7 @@ func TestYaml_StepSlice_ToPipeline(t *testing.T) { Target: []string{"production"}, }, Unless: pipeline.Rules{ - Branch: []string{"master"}, + Branch: []string{"main"}, Comment: []string{"real comment"}, Event: []string{"pull_request"}, Path: []string{"bar.txt"}, diff --git a/yaml/template.go b/yaml/template.go index 3e1ba38c..623a60db 100644 --- a/yaml/template.go +++ b/yaml/template.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/template_test.go b/yaml/template_test.go index 606277a5..39827760 100644 --- a/yaml/template_test.go +++ b/yaml/template_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/testdata/build.yml b/yaml/testdata/build.yml index 008bf989..e1a7fbc9 100644 --- a/yaml/testdata/build.yml +++ b/yaml/testdata/build.yml @@ -93,7 +93,7 @@ steps: pull: true ruleset: if: - branch: master + branch: main event: push operator: and secrets: diff --git a/yaml/testdata/ruleset_advanced.yml b/yaml/testdata/ruleset_advanced.yml index dfd92ca1..24039e2a 100644 --- a/yaml/testdata/ruleset_advanced.yml +++ b/yaml/testdata/ruleset_advanced.yml @@ -1,6 +1,6 @@ --- if: - branch: [ master ] + branch: [ main ] event: push tag: "^refs/tags/(\\d+\\.)+\\d+$" unless: diff --git a/yaml/testdata/ruleset_regex.yml b/yaml/testdata/ruleset_regex.yml index 794a03d5..eb6b1fd3 100644 --- a/yaml/testdata/ruleset_regex.yml +++ b/yaml/testdata/ruleset_regex.yml @@ -1,6 +1,6 @@ --- if: - branch: master + branch: main event: tag tag: [ "^refs/tags/(\\d+\\.)+\\d+$" ] operator: and diff --git a/yaml/testdata/ruleset_simple.yml b/yaml/testdata/ruleset_simple.yml index 21f5e5ab..7696e49b 100644 --- a/yaml/testdata/ruleset_simple.yml +++ b/yaml/testdata/ruleset_simple.yml @@ -1,5 +1,5 @@ --- -branch: master +branch: main comment: "test comment" continue: true event: push diff --git a/yaml/ulimit.go b/yaml/ulimit.go index acca9409..aa282212 100644 --- a/yaml/ulimit.go +++ b/yaml/ulimit.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/ulimit_test.go b/yaml/ulimit_test.go index 1e412943..46d28bde 100644 --- a/yaml/ulimit_test.go +++ b/yaml/ulimit_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/volume.go b/yaml/volume.go index 0d77c5a3..8370ee5c 100644 --- a/yaml/volume.go +++ b/yaml/volume.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/volume_test.go b/yaml/volume_test.go index 1aaec73d..dc7d9513 100644 --- a/yaml/volume_test.go +++ b/yaml/volume_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/worker.go b/yaml/worker.go index 8bdd3e84..0f7a3f8b 100644 --- a/yaml/worker.go +++ b/yaml/worker.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml diff --git a/yaml/worker_test.go b/yaml/worker_test.go index 4dc12f43..5bafd0c2 100644 --- a/yaml/worker_test.go +++ b/yaml/worker_test.go @@ -1,6 +1,4 @@ -// Copyright (c) 2022 Target Brands, Inc. All rights reserved. -// -// Use of this source code is governed by the LICENSE file in this repository. +// SPDX-License-Identifier: Apache-2.0 package yaml