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-words:
- 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.24.13
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.24.13
- 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: golangci/golangci-lint:latest
image: golang:1.24
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.24.13
- name: GOLANGCILINT_CACHE
value: $(workspaces.source.path)/go-build-cache/golangci-cache
script: |
Expand Down
30 changes: 23 additions & 7 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 (golangci-lint is currently on v1.x). Attempting to download this non-existent version will cause the curl command to fail with a 404 Not Found error, breaking both local development and CI linting. Since the Go toolchain is pinned to go1.24.13, please use a version of golangci-lint that supports Go 1.24, such as v1.64.5.

GOLANGCI_LINT_VERSION ?= v1.64.5

GO_TOOLCHAIN ?= go1.24.13
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
PY_FILES := $(shell find . -type f -regex ".*\.py" -not -regex ".*\.venv/.*" -print)
SH_FILES := $(shell find hack/ -type f -regex ".*\.sh" -not -regex ".*\.venv/.*" -print)
YAML_FILES := $(shell find . -not -regex '^./vendor/.*' -type f -regex ".*y[a]ml" -print)
Expand Down Expand Up @@ -81,13 +91,21 @@ html-coverage: ## generate html coverage
lint: lint-go lint-yaml lint-md lint-python lint-shell ## run all linters

.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: ${YAML_FILES} ## runs yamllint on all yaml files
@echo "Linting yaml files..."
Expand Down Expand Up @@ -144,9 +162,9 @@ fix-python-errors: ## fix all python errors generated by ruff
@[[ -n `git status --porcelain $(PY_FILES)` ]] && { echo "Python files has been cleaned 🧹. Cleaned Files: ";git status --porcelain $(PY_FILES) ;} || 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 Expand Up @@ -210,5 +228,3 @@ dev-docs: download-hugo ## preview live your docs with hugo
.PHONY: clean
clean: ## clean build artifacts
rm -fR bin


2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
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.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.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/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
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
9 changes: 5 additions & 4 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 @@ -1107,7 +1108,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 @@ -1123,7 +1124,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 @@ -1205,7 +1206,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
7 changes: 1 addition & 6 deletions pkg/adapter/sinker.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,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
4 changes: 2 additions & 2 deletions pkg/llm/providers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func BuildPrompt(request *ltypes.AnalysisRequest) (string, error) {
promptBuilder.WriteString("Context Information:\n")

for key, value := range request.Context {
promptBuilder.WriteString(fmt.Sprintf("=== %s ===\n", strings.ToUpper(key)))
fmt.Fprintf(&promptBuilder, "=== %s ===\n", strings.ToUpper(key))

switch v := value.(type) {
case string:
Expand All @@ -118,7 +118,7 @@ func BuildPrompt(request *ltypes.AnalysisRequest) (string, error) {
}
promptBuilder.Write(jsonData)
default:
promptBuilder.WriteString(fmt.Sprintf("%v", v))
fmt.Fprintf(&promptBuilder, "%v", v)
}

promptBuilder.WriteString("\n\n")
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