from file

This commit is contained in:
Mael G. 2025-01-06 22:04:50 +01:00
parent fcd7f83555
commit 7ad3a171c0
2 changed files with 40 additions and 42 deletions

View file

@ -1,46 +1,32 @@
pipeline:
lint-go:
image: golangci/golangci-lint
group: lint-build
commands:
- golangci-lint run *.go --enable=gofumpt
when:
path: "*.go"
lint-docker:
image: hadolint/hadolint:latest-debian
group: lint-build
commands:
- hadolint --ignore DL3003 Dockerfile
when:
path: "Dockerfile"
build-go:
image: golang
group: lint-build
commands:
- go build
when:
path: ["Dockerfile", "*.go"]
build-docker-pr:
image: plugins/kaniko
steps:
- name: publish_image
image: woodpeckerci/plugin-docker-buildx
settings:
repo: mcs94/gitea-comment
tags: latest
repo: git.gnous.eu/${CI_REPO_OWNER}/gitea-comment-plugin
dockerfile: Dockerfile
no_push: true
when:
event: pull_request
branch: main
path: ["Dockerfile", "*.go"]
build-docker:
image: plugins/kaniko
settings:
repo: mcs94/gitea-comment
tags: latest
dockerfile: Dockerfile
username: mcs94
platforms: linux/amd64
registry: https://git.gnous.eu
tag: ${CI_COMMIT}
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event: [push, tag]
branch: main
path: ["Dockerfile", "*.go"]
branch: ${CI_REPO_DEFAULT_BRANCH}
event: push
- name: publish_image_tag
image: woodpeckerci/plugin-docker-buildx
settings:
repo: git.gnous.eu/${CI_REPO_OWNER}/gitea-comment-plugin
dockerfile: Dockerfile
platforms: linux/amd64
registry: https://git.gnous.eu
tags:
- ${CI_COMMIT_TAG##v} # Remove v from tag
- stable
username:
from_secret: docker_username
password:
from_secret: docker_password
when:
event: tag

14
main.go
View file

@ -37,6 +37,7 @@ func main() {
var giteaToken string
var giteaAddress string
var comment string
var commentFile string
var repoOwner string
var repoName string
var prIndex int
@ -44,15 +45,26 @@ func main() {
flag.StringVar(&giteaToken, "gitea-token", LookupEnvOrString("PLUGIN_GITEA_TOKEN", giteaToken), "API token for Gitea")
flag.StringVar(&giteaAddress, "gitea-address", LookupEnvOrString("PLUGIN_GITEA_ADDRESS", giteaAddress), "Gitea URL")
flag.StringVar(&comment, "comment", LookupEnvOrString("PLUGIN_COMMENT", comment), "Comment for Gitea")
flag.StringVar(&commentFile, "comment-file", LookupEnvOrString("PLUGIN_COMMENT_FILE", commentFile), "Comment file for Gitea")
flag.StringVar(&repoOwner, "repo-owner", LookupEnvOrString("CI_REPO_OWNER", repoOwner), "Owner of the repository")
flag.StringVar(&repoName, "repo-name", LookupEnvOrString("CI_REPO_NAME", repoName), "Name of the repository")
flag.IntVar(&prIndex, "pr-index", LookupEnvOrInt("CI_COMMIT_PULL_REQUEST", prIndex), "Index of the PR")
flag.Parse()
if comment == "" {
if comment == "" || commentFile != "" {
panic("You must provide a comment")
}
if commentFile != "" && comment != "" {
panic("You must provide only one of comment or comment-file")
}
if commentFile != "" {
commentBytes, err := os.ReadFile(commentFile)
if err != nil {
panic(err)
}
comment = string(commentBytes)
}
if giteaToken == "" {
panic("You must provide a Gitea API Token")
}