Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ linters:
- whitespace
- zerologlint
settings:
govet:
disable:
- inline
misspell:
ignore-rules:
- cancelled
Expand Down
8 changes: 7 additions & 1 deletion .tekton/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ spec:
value: $(workspaces.source.path)/go-build-cache/cache
- name: GOMODCACHE
value: $(workspaces.source.path)/go-build-cache/mod
- name: GOTOOLCHAIN
value: go1.25.0
workingDir: $(workspaces.source.path)
script: |
#!/usr/bin/env bash
Expand All @@ -82,6 +84,8 @@ spec:
value: $(workspaces.source.path)/go-build-cache/cache
- name: GOMODCACHE
value: $(workspaces.source.path)/go-build-cache/mod
- name: GOTOOLCHAIN
value: go1.25.0
- name: GITHUB_REPOSITORY
value: "{{repo_owner}}/{{repo_name}}"
- name: GITHUB_PULL_REQUEST_ID
Expand All @@ -97,13 +101,15 @@ spec:
chmod +x ./codecov
./codecov -P $GITHUB_PULL_REQUEST_ID -C {{revision}} -v
- name: lint
image: docker.io/golangci/golangci-lint:v2.10.1
image: docker.io/golang:1.25
workingDir: $(workspaces.source.path)
env:
- name: GOCACHE
value: $(workspaces.source.path)/go-build-cache/cache
- name: GOMODCACHE
value: $(workspaces.source.path)/go-build-cache/mod
- name: GOTOOLCHAIN
value: go1.25.0
- name: GOLANGCILINT_CACHE
value: $(workspaces.source.path)/go-build-cache/golangci-cache
script: |
Expand Down
28 changes: 23 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TARGET_NAMESPACE=pipelines-as-code
HUGO_VERSION=0.96.0
GOLANGCI_LINT=golangci-lint
GOLANGCI_LINT_VERSION ?= v2.12.2
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The version v2.12.2 for golangci-lint does not exist. The official golangci-lint releases use v1.y.z versioning (e.g., v1.62.2). Using an invalid version will cause the curl download command to fail with a 404 error, breaking the linting process.

GOLANGCI_LINT_VERSION ?= v1.62.2

GO_TOOLCHAIN ?= go1.25.0
GOFUMPT=gofumpt
TKN_BINARY_NAME := tkn
TKN_BINARY_URL := https://tekton.dev/docs/cli/\#installation
Expand All @@ -11,11 +12,20 @@ TIMEOUT_UNIT = 20m
TIMEOUT_E2E = 45m
DEFAULT_GO_TEST_FLAGS := -race -failfast
GO_TEST_FLAGS :=
GOTOOLCHAIN ?= $(GO_TOOLCHAIN)
export GOTOOLCHAIN

SHELL := bash
TOPDIR := $(shell git rev-parse --show-toplevel)
TMPDIR := $(TOPDIR)/tmp
HUGO_BIN := $(TMPDIR)/hugo/hugo
GOLANGCI_LINT_OS ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
GOLANGCI_LINT_ARCH ?= $(shell uname -m | sed -e 's/x86_64/amd64/' -e 's/aarch64/arm64/')
GOLANGCI_LINT_PACKAGE := golangci-lint-$(patsubst v%,%,$(GOLANGCI_LINT_VERSION))-$(GOLANGCI_LINT_OS)-$(GOLANGCI_LINT_ARCH)
GOLANGCI_LINT_DIR := $(TMPDIR)/golangci-lint/$(GOLANGCI_LINT_VERSION)
GOLANGCI_LINT_BIN := $(GOLANGCI_LINT_DIR)/golangci-lint
GOLANGCI_LINT ?= $(GOLANGCI_LINT_BIN)
GOLANGCI_LINT_EXTRA_ARGS ?= --concurrency=1

# Safe file list helpers using null-delimited output
# Usage: $(call GIT_LS_FILES,<patterns>,<command>)
Expand Down Expand Up @@ -91,13 +101,21 @@ lint-e2e-naming: ## check e2e test naming conventions
@./hack/check-e2e-test-naming.sh

.PHONY: lint-go
lint-go: ## runs go linter on all go files
lint-go: golangci-lint ## runs go linter on all go files
@echo "Linting go files..."
@$(GOLANGCI_LINT) run ./pkg/... ./test/... --modules-download-mode=vendor \
@$(GOLANGCI_LINT) run $(GOLANGCI_LINT_EXTRA_ARGS) ./pkg/... ./test/... --modules-download-mode=vendor \
--max-issues-per-linter=0 \
--max-same-issues=0 \
--timeout $(TIMEOUT_UNIT)

.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT_BIN) ## download pinned golangci-lint into tmp

$(GOLANGCI_LINT_BIN):
@mkdir -p $(GOLANGCI_LINT_DIR)
@echo "Downloading golangci-lint $(GOLANGCI_LINT_VERSION) for $(GOLANGCI_LINT_OS)-$(GOLANGCI_LINT_ARCH)"
@curl -fsSL "https://github.com/golangci/golangci-lint/releases/download/$(GOLANGCI_LINT_VERSION)/$(GOLANGCI_LINT_PACKAGE).tar.gz" | tar -xz -C "$(GOLANGCI_LINT_DIR)" --strip-components=1 "$(GOLANGCI_LINT_PACKAGE)/golangci-lint"

.PHONY: lint-yaml
lint-yaml: ## runs yamllint on all yaml files
@echo "Linting yaml files..."
Expand Down Expand Up @@ -156,9 +174,9 @@ fix-python-errors: ## fix all python errors generated by ruff
[[ -n "$$STATUS" ]] && { echo "Python files has been cleaned 🧹. Cleaned Files: "; echo "$$STATUS" ;} || echo "Python files are clean ✨"

.PHONY: fix-golangci-lint
fix-golangci-lint: ## run golangci-lint and fix on all go files
fix-golangci-lint: golangci-lint ## run golangci-lint and fix on all go files
@echo "Fixing some golangi-lint files..."
@$(GOLANGCI_LINT) run ./... --modules-download-mode=vendor \
@$(GOLANGCI_LINT) run $(GOLANGCI_LINT_EXTRA_ARGS) ./... --modules-download-mode=vendor \
--max-issues-per-linter=0 \
--max-same-issues=0 \
--timeout $(TIMEOUT_UNIT) \
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.10.2
github.com/stretchr/testify v1.11.1
github.com/tektoncd/pipeline v1.9.2
github.com/tektoncd/pipeline v1.9.3
gitlab.com/gitlab-org/api/client-go v1.14.0
go.opencensus.io v0.24.0
go.uber.org/zap v1.27.1
Expand All @@ -54,8 +54,8 @@ require (
github.com/cloudevents/sdk-go/sql/v2 v2.16.2 // indirect
github.com/coreos/go-oidc/v3 v3.17.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
github.com/go-jose/go-jose/v3 v3.0.5 // indirect
github.com/go-jose/go-jose/v4 v4.1.4 // indirect
github.com/go-openapi/swag/cmdutils v0.25.4 // indirect
github.com/go-openapi/swag/conv v0.25.4 // indirect
github.com/go-openapi/swag/fileutils v0.25.4 // indirect
Expand Down Expand Up @@ -154,7 +154,7 @@ require (
)

replace (
github.com/go-jose/go-jose/v4 => github.com/go-jose/go-jose/v4 v4.0.5
github.com/go-jose/go-jose/v4 => github.com/go-jose/go-jose/v4 v4.1.4
github.com/google/gnostic-models => github.com/google/gnostic-models v0.6.9
k8s.io/api => k8s.io/api v0.32.8
k8s.io/apimachinery => k8s.io/apimachinery v0.32.8
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e/go.mod h1:RCMrTZv
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-jose/go-jose/v3 v3.0.4 h1:Wp5HA7bLQcKnf6YYao/4kpRpVMp/yf6+pJKV8WFSaNY=
github.com/go-jose/go-jose/v3 v3.0.4/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE=
github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA=
github.com/go-jose/go-jose/v3 v3.0.5 h1:BLLJWbC4nMZOfuPVxoZIxeYsn6Nl2r1fITaJ78UQlVQ=
github.com/go-jose/go-jose/v3 v3.0.5/go.mod h1:5b+7YgP7ZICgJDBdfjZaIt+H/9L9T/YQrVfLAMboGkQ=
github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA=
github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
Expand Down Expand Up @@ -482,8 +482,8 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/stvp/go-udp-testing v0.0.0-20201019212854-469649b16807/go.mod h1:7jxmlfBCDBXRzr0eAQJ48XC1hBu1np4CS5+cHEYfwpc=
github.com/tektoncd/pipeline v1.9.2 h1:uKEt6CGLmkeKLdKIZnel0gn8lfQ1P7+398yystdBuHU=
github.com/tektoncd/pipeline v1.9.2/go.mod h1:PTlIZ4Mhr8HZDx404O7spJtafiynetTMedCsXStjtHk=
github.com/tektoncd/pipeline v1.9.3 h1:7Z+V2VX5wjz9LoNa16E1RbgH9mpYy5B1KnAMm3H0czc=
github.com/tektoncd/pipeline v1.9.3/go.mod h1:pEruzPp4JM8JK8Nnnih46IPgdtxRPot/i9pUZo8lA9I=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
Expand Down
3 changes: 2 additions & 1 deletion pkg/adapter/incoming.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (l *listener) detectIncoming(ctx context.Context, req *http.Request, payloa
return false, nil, nil
}

l.logger.Infof("incoming request has been requested: %v", req.URL)
l.logger.Infof("incoming request has been requested: %v", req.URL.Path)
payload, err := parseIncomingPayload(req, payloadBody)
if payload.legacyMode {
// Log this, even if the request is invalid
Expand Down Expand Up @@ -183,6 +183,7 @@ func (l *listener) detectIncoming(ctx context.Context, req *http.Request, payloa
return false, nil, err
}
l.event.Provider.URL = enterpriseURL
l.event.GHEURL = enterpriseURL
l.event.Provider.Token = token
l.event.InstallationID = installationID
// Github app is not installed for provided repository url
Expand Down
11 changes: 6 additions & 5 deletions pkg/adapter/incoming_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adapter

import (
"context"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -833,7 +834,7 @@ func Test_listener_detectIncoming(t *testing.T) {
}

// make a new request
req := httptest.NewRequest(tt.args.method,
req := httptest.NewRequestWithContext(context.Background(), tt.args.method,
fmt.Sprintf("http://localhost%s?repository=%s&secret=%s&pipelinerun=%s&branch=%s&namespace=%s", tt.args.queryURL,
tt.args.queryRepository, tt.args.querySecret, tt.args.queryPipelineRun, tt.args.queryBranch, tt.args.queryNamespace),
strings.NewReader(tt.args.incomingBody))
Expand Down Expand Up @@ -1121,7 +1122,7 @@ func Test_detectIncoming_legacy_warning(t *testing.T) {
}{
{
name: "legacy mode - params in URL",
req: httptest.NewRequest(http.MethodPost,
req: httptest.NewRequestWithContext(context.Background(), http.MethodPost,
"http://localhost/incoming?repository=test-good&secret=verysecrete&pipelinerun=pipelinerun1&branch=main",
strings.NewReader("")),
body: nil,
Expand All @@ -1137,7 +1138,7 @@ func Test_detectIncoming_legacy_warning(t *testing.T) {
"secret": "verysecrete",
"params": {"foo": "bar"}
}`
r := httptest.NewRequest(http.MethodPost,
r := httptest.NewRequestWithContext(context.Background(), http.MethodPost,
"http://localhost/incoming",
strings.NewReader(payload))
r.Header.Set("Content-Type", "application/json")
Expand Down Expand Up @@ -1219,7 +1220,7 @@ func Test_detectIncoming_body_params_are_parsed(t *testing.T) {
"secret": "verysecrete",
"params": {"foo": "bar", "bar": "baz"}
}`
req := httptest.NewRequest(http.MethodPost,
req := httptest.NewRequestWithContext(context.Background(), http.MethodPost,
"http://localhost/incoming",
strings.NewReader(payload))
req.Header.Set("Content-Type", "application/json")
Expand Down Expand Up @@ -1323,7 +1324,7 @@ func Test_parseIncomingPayload(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
req := httptest.NewRequest(tt.method, tt.url, strings.NewReader(tt.body))
req := httptest.NewRequestWithContext(context.Background(), tt.method, tt.url, strings.NewReader(tt.body))
if tt.headers != nil {
req.Header = tt.headers
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/adapter/sinker.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ func (s *sinker) processEventPayload(ctx context.Context, request *http.Request)
}

func (s *sinker) processEvent(ctx context.Context, request *http.Request) error {
if s.event.EventType == "incoming" {
if request.Header.Get("X-GitHub-Enterprise-Host") != "" {
s.event.Provider.URL = request.Header.Get("X-GitHub-Enterprise-Host")
s.event.GHEURL = request.Header.Get("X-GitHub-Enterprise-Host")
}
} else {
if s.event.EventType != "incoming" {
if err := s.processEventPayload(ctx, request); err != nil {
return err
}
Expand Down
10 changes: 7 additions & 3 deletions pkg/provider/github/app/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/golang-jwt/jwt/v4"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/keys"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
"github.com/openshift-pipelines/pipelines-as-code/pkg/params"
"github.com/openshift-pipelines/pipelines-as-code/pkg/provider/github"
Expand Down Expand Up @@ -67,9 +68,12 @@ func (ip *Install) GetAndUpdateInstallationID(ctx context.Context) (string, stri
return "", "", 0, fmt.Errorf("github client APIURL is nil")
}
apiURL := *ip.ghClient.APIURL
enterpriseHost := ip.request.Header.Get("X-GitHub-Enterprise-Host")
if enterpriseHost != "" {
apiURL = fmt.Sprintf("https://%s/api/v3", strings.TrimSuffix(enterpriseHost, "/"))
enterpriseHost := ""
if repoURL.Host != "" && repoURL.Host != "github.com" {
enterpriseHost = repoURL.Host
if apiURL == keys.PublicGithubAPIURL {
apiURL = fmt.Sprintf("https://%s/api/v3", strings.TrimSuffix(enterpriseHost, "/"))
}
}

client, _, _ := github.MakeClient(ctx, apiURL, jwtToken)
Expand Down
Loading
Loading