refactor: initial commit after rewrite to woodpecker

This commit is contained in:
Robert Kaussow 2023-08-17 13:22:46 +02:00
parent 880ae9399c
commit e7f2e6f9e6
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
23 changed files with 419 additions and 504 deletions

View File

@ -2,7 +2,7 @@ style: github
template: CHANGELOG.tpl.md
info:
title: CHANGELOG
repository_url: https://github.com/thegeeklab/drone-github-comment
repository_url: https://github.com/thegeeklab/wp-github-comment
options:
commit_groups:
title_maps:

View File

@ -2,4 +2,4 @@ api
github
url
gh
drone-github-comment
wp-github-comment

View File

@ -1,297 +0,0 @@
---
kind: pipeline
name: test
platform:
os: linux
arch: amd64
steps:
- name: deps
image: golang:1.20
commands:
- make deps
volumes:
- name: godeps
path: /go
- name: lint
image: golang:1.20
commands:
- make lint
volumes:
- name: godeps
path: /go
- name: test
image: golang:1.20
commands:
- make test
volumes:
- name: godeps
path: /go
volumes:
- name: godeps
temp: {}
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
---
kind: pipeline
name: build-binaries
platform:
os: linux
arch: amd64
steps:
- name: build
image: techknowlogick/xgo:go-1.20.x
commands:
- ln -s /drone/src /source
- make release
- name: executable
image: alpine
commands:
- $(find dist/ -executable -type f -iname ${DRONE_REPO_NAME}-linux-amd64) --help
- name: changelog-generate
image: thegeeklab/git-chglog
commands:
- git fetch -tq
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}
- name: changelog-format
image: thegeeklab/alpine-tools
commands:
- prettier CHANGELOG.md
- prettier -w CHANGELOG.md
- name: publish
image: plugins/github-release
settings:
api_key:
from_secret: github_token
files:
- dist/*
note: CHANGELOG.md
overwrite: true
title: ${DRONE_TAG}
when:
ref:
- refs/tags/**
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
depends_on:
- test
---
kind: pipeline
name: build-container
platform:
os: linux
arch: amd64
steps:
- name: dryrun
image: thegeeklab/drone-docker-buildx:23
settings:
dockerfile: Dockerfile.multiarch
dry_run: true
platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
provenance: false
repo: thegeeklab/${DRONE_REPO_NAME}
when:
ref:
- refs/pull/**
- name: publish-dockerhub
image: thegeeklab/drone-docker-buildx:23
settings:
auto_tag: true
dockerfile: Dockerfile.multiarch
password:
from_secret: docker_password
platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
provenance: false
repo: thegeeklab/${DRONE_REPO_NAME}
username:
from_secret: docker_username
when:
ref:
- refs/heads/main
- refs/tags/**
depends_on:
- dryrun
- name: publish-quay
image: thegeeklab/drone-docker-buildx:23
settings:
auto_tag: true
dockerfile: Dockerfile.multiarch
password:
from_secret: quay_password
platforms:
- linux/amd64
- linux/arm64
- linux/arm/v7
- linux/arm/v6
provenance: false
registry: quay.io
repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
username:
from_secret: quay_username
when:
ref:
- refs/heads/main
- refs/tags/**
depends_on:
- dryrun
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
depends_on:
- test
---
kind: pipeline
name: docs
platform:
os: linux
arch: amd64
concurrency:
limit: 1
steps:
- name: markdownlint
image: thegeeklab/markdownlint-cli
commands:
- markdownlint 'docs/content/**/*.md' 'README.md' 'CONTRIBUTING.md'
- name: spellcheck
image: thegeeklab/alpine-tools
commands:
- spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions
environment:
FORCE_COLOR: true
NPM_CONFIG_LOGLEVEL: error
- name: publish
image: thegeeklab/drone-git-action
settings:
action:
- pages
author_email: bot@thegeeklab.de
author_name: thegeeklab-bot
branch: docs
message: auto-update documentation
netrc_password:
from_secret: github_token
pages_directory: _docs/
when:
ref:
- refs/heads/main
trigger:
ref:
- refs/heads/main
- refs/tags/**
- refs/pull/**
depends_on:
- build-binaries
- build-container
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: pushrm-dockerhub
image: chko/docker-pushrm:1
environment:
DOCKER_PASS:
from_secret: docker_password
DOCKER_USER:
from_secret: docker_username
PUSHRM_FILE: README.md
PUSHRM_SHORT: Drone plugin to add comments to GitHub Issues and Pull Requests
PUSHRM_TARGET: thegeeklab/${DRONE_REPO_NAME}
when:
status:
- success
- name: pushrm-quay
image: chko/docker-pushrm:1
environment:
APIKEY__QUAY_IO:
from_secret: quay_token
PUSHRM_FILE: README.md
PUSHRM_TARGET: quay.io/thegeeklab/${DRONE_REPO_NAME}
when:
status:
- success
- name: matrix
image: thegeeklab/drone-matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
template: "Status: **{{ .Build.Status }}**<br/> Build: [{{ .Repo.Owner }}/{{ .Repo.Name }}]({{ .Build.Link }}){{ if .Build.Branch }} ({{ .Build.Branch }}){{ end }} by {{ .Commit.Author }}<br/> Message: {{ .Commit.Message.Title }}"
username:
from_secret: matrix_username
when:
status:
- success
- failure
trigger:
ref:
- refs/heads/main
- refs/tags/**
status:
- success
- failure
depends_on:
- docs
---
kind: signature
hmac: 9ac1492179476c9cf4a427944d50f2771ad9a3b47faa7e27f636bc083107f6a1
...

15
.github/settings.yml vendored
View File

@ -1,8 +1,8 @@
repository:
name: drone-github-comment
description: Drone plugin to add comments to GitHub Issues and Pull Requests
homepage: https://drone-plugin-index.geekdocs.de/plugins/drone-github-comment
topics: drone, drone-plugin
name: wp-github-comment
description: Woodpecker CI plugin to add comments to GitHub Issues and Pull Requests
homepage: https://wp-plugin-index.geekdocs.de/plugins/wp-github-comment
topics: woodpecker-ci, woodpecker, woodpecker-plugin
private: false
has_issues: true
@ -51,8 +51,11 @@ branches:
required_status_checks:
strict: false
contexts:
- continuous-integration/drone/pr
enforce_admins: true
- ci/woodpecker/pr/test
- ci/woodpecker/pr/build-binary
- ci/woodpecker/pr/build-container
- ci/woodpecker/pr/docs
enforce_admins: false
required_linear_history: true
restrictions: null
- name: docs

2
.gitignore vendored
View File

@ -1,6 +1,6 @@
/dist/
/release/
/drone-github-comment*
/wp-github-comment*
coverage.out
CHANGELOG.md

View File

@ -1,3 +1,2 @@
.drone.yml
*.tpl.md
LICENSE

View File

@ -0,0 +1,44 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
build:
image: docker.io/techknowlogick/xgo:go-1.20.x
commands:
- ln -s $(pwd) /source
- make release
executable:
image: docker.io/library/alpine
commands:
- $(find dist/ -executable -type f -iname ${CI_REPO_NAME}-linux-amd64) --help
changelog-generate:
image: quay.io/thegeeklab/git-chglog
commands:
- git fetch -tq
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${CI_COMMIT_TAG:---next-tag unreleased unreleased}
changelog-format:
image: quay.io/thegeeklab/alpine-tools
commands:
- prettier CHANGELOG.md
- prettier -w CHANGELOG.md
publish-github:
image: docker.io/plugins/github-release
settings:
api_key:
from_secret: github_token
note: CHANGELOG.md
overwrite: true
title: ${CI_COMMIT_TAG}
when:
- event: [tag]
depends_on:
- test

View File

@ -0,0 +1,66 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
dryrun:
image: quay.io/thegeeklab/wp-docker-buildx
settings:
containerfile: Containerfile.multiarch
dry_run: true
platforms:
- linux/amd64
- linux/arm64
provenance: false
repo: ${CI_REPO}
when:
- event: [pull_request]
publish-dockerhub:
group: container
image: quay.io/thegeeklab/wp-docker-buildx
settings:
auto_tag: true
containerfile: Containerfile.multiarch
password:
from_secret: docker_password
platforms:
- linux/amd64
- linux/arm64
provenance: false
repo: ${CI_REPO}
username:
from_secret: docker_username
when:
- event: [tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
publish-quay:
group: container
image: quay.io/thegeeklab/wp-docker-buildx
settings:
auto_tag: true
containerfile: Containerfile.multiarch
password:
from_secret: quay_password
platforms:
- linux/amd64
- linux/arm64
provenance: false
registry: quay.io
repo: quay.io/${CI_REPO}
username:
from_secret: quay_username
when:
- event: [tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
depends_on:
- test

72
.woodpecker/docs.yml Normal file
View File

@ -0,0 +1,72 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
markdownlint:
image: quay.io/thegeeklab/markdownlint-cli
commands:
- markdownlint 'README.md' 'CONTRIBUTING.md'
spellcheck:
image: quay.io/thegeeklab/alpine-tools
commands:
- spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls --no-suggestions
environment:
FORCE_COLOR: "true"
NPM_CONFIG_LOGLEVEL: "error"
publish:
image: quay.io/thegeeklab/wp-git-action
settings:
action:
- pages
author_email: bot@thegeeklab.de
author_name: thegeeklab-bot
branch: docs
message: "[skip ci] auto-update documentation"
netrc_password:
from_secret: github_token
pages_directory: _docs/
when:
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
pushrm-dockerhub:
image: docker.io/chko/docker-pushrm:1
secrets:
- source: docker_password
target: DOCKER_PASS
- source: docker_username
target: DOCKER_USER
environment:
PUSHRM_FILE: README.md
PUSHRM_SHORT: Woodpecker CI plugin to add comments to GitHub Issues and Pull Requests
PUSHRM_TARGET: ${CI_REPO}
when:
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
status: [success]
pushrm-quay:
image: docker.io/chko/docker-pushrm:1
secrets:
- source: quay_token
target: APIKEY__QUAY_IO
environment:
PUSHRM_FILE: README.md
PUSHRM_TARGET: quay.io/${CI_REPO}
when:
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
status: [success]
depends_on:
- build-binary
- build-container

26
.woodpecker/notify.yml Normal file
View File

@ -0,0 +1,26 @@
---
when:
- event: [tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
runs_on: [success, failure]
steps:
matrix:
image: quay.io/thegeeklab/wp-matrix
settings:
homeserver:
from_secret: matrix_homeserver
password:
from_secret: matrix_password
roomid:
from_secret: matrix_roomid
username:
from_secret: matrix_username
when:
- status: [success, failure]
depends_on:
- docs

22
.woodpecker/test.yml Normal file
View File

@ -0,0 +1,22 @@
---
when:
- event: [pull_request, tag]
- event: [push, manual]
branch:
- ${CI_REPO_DEFAULT_BRANCH}
steps:
deps:
image: docker.io/library/golang:1.20
commands:
- make deps
lint:
image: docker.io/library/golang:1.20
commands:
- make lint
test:
image: docker.io/library/golang:1.20
commands:
- make test

View File

@ -12,10 +12,10 @@ FROM alpine:3.18@sha256:7144f7bab3d4c2648d7e59409f15ec52a18006a128c733fcff20d3a4
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
LABEL org.opencontainers.image.title="drone-github-comment"
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-github-comment"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-github-comment"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-github-comment"
LABEL org.opencontainers.image.title="wp-github-comment"
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/wp-github-comment"
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/wp-github-comment"
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/wp-github-comment"
COPY --from=build /src/dist/drone-github-comment /bin/drone-github-comment
ENTRYPOINT ["/bin/drone-github-comment"]
COPY --from=build /src/dist/wp-github-comment /bin/wp-github-comment
ENTRYPOINT ["/bin/wp-github-comment"]

View File

@ -3,7 +3,7 @@ GOFUMPT_PACKAGE_VERSION := v0.5.0
# renovate: datasource=github-releases depName=golangci/golangci-lint
GOLANGCI_LINT_PACKAGE_VERSION := v1.53.3
EXECUTABLE := drone-github-comment
EXECUTABLE := wp-github-comment
DIST := dist
DIST_DIRS := $(DIST)
@ -30,8 +30,8 @@ endif
TAGS ?= netgo
ifndef VERSION
ifneq ($(DRONE_TAG),)
VERSION ?= $(subst v,,$(DRONE_TAG))
ifneq ($(CI_COMMIT_TAG),)
VERSION ?= $(subst v,,$(CI_COMMIT_TAG))
else
VERSION ?= $(shell git rev-parse --short HEAD)
endif

View File

@ -1,21 +1,21 @@
# drone-github-comment
# wp-github-comment
Drone plugin to add comments to GitHub Issues and Pull Requests
Woodpecker CI plugin to add comments to GitHub Issues and Pull Requests
[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-github-comment?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-github-comment)
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-github-comment)
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/drone-github-comment)
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/drone-github-comment)](https://goreportcard.com/report/github.com/thegeeklab/drone-github-comment)
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-github-comment)](https://github.com/thegeeklab/drone-github-comment/graphs/contributors)
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-github-comment)
[![License: MIT](https://img.shields.io/github/license/thegeeklab/drone-github-comment)](https://github.com/thegeeklab/drone-github-comment/blob/main/LICENSE)
[![Build Status](https://img.shields.io/wp/build/thegeeklab/wp-github-comment?logo=wp&server=https%3A%2F%2Fwp.thegeeklab.de)](https://wp.thegeeklab.de/thegeeklab/wp-github-comment)
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/wp-github-comment)
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/wp-github-comment)
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/wp-github-comment)](https://goreportcard.com/report/github.com/thegeeklab/wp-github-comment)
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/wp-github-comment)](https://github.com/thegeeklab/wp-github-comment/graphs/contributors)
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/wp-github-comment)
[![License: MIT](https://img.shields.io/github/license/thegeeklab/wp-github-comment)](https://github.com/thegeeklab/wp-github-comment/blob/main/LICENSE)
Drone plugin to add comments to GitHub Issues and Pull Requests. You can find the full documentation at [https://drone-plugin-index.geekdocs.de](https://drone-plugin-index.geekdocs.de/plugins/drone-github-comment).
Woodpecker CI plugin to add comments to GitHub Issues and Pull Requests. You can find the full documentation at [https://wp-plugin-index.geekdocs.de](https://wp-plugin-index.geekdocs.de/plugins/wp-github-comment).
## Contributors
Special thanks to all [contributors](https://github.com/thegeeklab/drone-github-comment/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/drone-github-comment/blob/main/CONTRIBUTING.md).
Special thanks to all [contributors](https://github.com/thegeeklab/wp-github-comment/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/wp-github-comment/blob/main/CONTRIBUTING.md).
## License
This project is licensed under the MIT License - see the [LICENSE](https://github.com/thegeeklab/drone-github-comment/blob/main/LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](https://github.com/thegeeklab/wp-github-comment/blob/main/LICENSE) file for details.

View File

@ -1,15 +1,16 @@
---
title: drone-github-comment
title: wp-github-comment
---
[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-github-comment?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-github-comment)
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-github-comment)
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/drone-github-comment)
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-github-comment)](https://github.com/thegeeklab/drone-github-comment/graphs/contributors)
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-github-comment)
[![License: MIT](https://img.shields.io/github/license/thegeeklab/drone-github-comment)](https://github.com/thegeeklab/drone-github-comment/blob/main/LICENSE)
[![Build Status](https://img.shields.io/wp/build/thegeeklab/wp-github-comment?logo=wp&server=https%3A%2F%2Fwp.thegeeklab.de)](https://wp.thegeeklab.de/thegeeklab/wp-github-comment)
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/wp-github-comment)
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/wp-github-comment)
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/wp-github-comment)](https://goreportcard.com/report/github.com/thegeeklab/wp-github-comment)
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/wp-github-comment)](https://github.com/thegeeklab/wp-github-comment/graphs/contributors)
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/wp-github-comment)
[![License: MIT](https://img.shields.io/github/license/thegeeklab/wp-github-comment)](https://github.com/thegeeklab/wp-github-comment/blob/main/LICENSE)
Drone plugin to add comments to GitHub Issues and Pull Requests.
Woodpecker CI plugin to add comments to GitHub Issues and Pull Requests.
<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
@ -29,7 +30,7 @@ name: default
steps:
- name: pr-comment
image: thegeeklab/drone-github-comment
image: thegeeklab/wp-github-comment
settings:
api_key: ghp_3LbMg9Kncpdkhjp3bh3dMnKNXLjVMTsXk4sM
message: "CI run completed successfully"
@ -40,7 +41,7 @@ steps:
<!-- prettier-ignore-start -->
<!-- spellchecker-disable -->
{{< propertylist name=drone-github-comment.data sort=name >}}
{{< propertylist name=wp-github-comment.data sort=name >}}
<!-- spellchecker-enable -->
<!-- prettier-ignore-end -->
@ -48,32 +49,27 @@ steps:
Build the binary with the following command:
```Shell
export GOOS=linux
export GOARCH=amd64
export CGO_ENABLED=0
export GO111MODULE=on
```shell
make build
```
Build the Docker image with the following command:
Build the container image with the following command:
```Shell
docker build --file docker/Dockerfile.amd64 --tag thegeeklab/drone-github-comment .
```shell
docker build --file Containerfile.multiarch --tag thegeeklab/wp-github-comment .
```
## Test
```Shell
docker run --rm \
-e DRONE_BUILD_EVENT=pull_request \
-e DRONE_REPO_OWNER=octocat \
-e DRONE_REPO_NAME=foo \
-e DRONE_PULL_REQUEST=1
-e CI_PIPELINE_EVENT=pull_request \
-e CI_REPO_OWNER=octocat \
-e CI_REPO_NAME=foo \
-e CI_COMMIT_PULL_REQUEST=1
-e PLUGIN_API_KEY=abc123 \
-e PLUGIN_MESSAGE="Demo comment" \
-v $(pwd):$(pwd) \
-w $(pwd) \
thegeeklab/drone-github-comment
-v $(pwd):/build:z \
-w /build \
thegeeklab/wp-github-comment
```

View File

@ -1,64 +0,0 @@
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
"github.com/sirupsen/logrus"
"github.com/thegeeklab/drone-github-comment/plugin"
"github.com/thegeeklab/drone-plugin-lib/v2/urfave"
"github.com/urfave/cli/v2"
)
//nolint:gochecknoglobals
var (
BuildVersion = "devel"
BuildDate = "00000000"
)
func main() {
settings := &plugin.Settings{}
if _, err := os.Stat("/run/drone/env"); err == nil {
_ = godotenv.Overload("/run/drone/env")
}
cli.VersionPrinter = func(c *cli.Context) {
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
}
app := &cli.App{
Name: "drone-github-comment",
Usage: "handle comments to github issues or pull requests",
Version: BuildVersion,
Flags: append(settingsFlags(settings, urfave.FlagsPluginCategory), urfave.Flags()...),
Action: run(settings),
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(settings *plugin.Settings) cli.ActionFunc {
return func(ctx *cli.Context) error {
urfave.LoggingFromContext(ctx)
plugin := plugin.New(
*settings,
urfave.PipelineFromContext(ctx),
urfave.NetworkFromContext(ctx),
)
if err := plugin.Validate(); err != nil {
return fmt.Errorf("validation failed: %w", err)
}
if err := plugin.Execute(); err != nil {
return fmt.Errorf("execution failed: %w", err)
}
return nil
}
}

View File

@ -1,7 +1,7 @@
package main
import (
"github.com/thegeeklab/drone-github-comment/plugin"
"github.com/thegeeklab/wp-github-comment/plugin"
"github.com/urfave/cli/v2"
)

View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"github.com/thegeeklab/wp-github-comment/plugin"
wp "github.com/thegeeklab/wp-plugin-go/plugin"
)
//nolint:gochecknoglobals
var (
BuildVersion = "devel"
BuildDate = "00000000"
)
func main() {
settings := &plugin.Settings{}
options := wp.Options{
Name: "wp-github-comment",
Description: "Add comments to GitHub Issues and Pull Requests",
Version: BuildVersion,
VersionMetadata: fmt.Sprintf("date=%s", BuildDate),
Flags: settingsFlags(settings, wp.FlagsPluginCategory),
}
plugin.New(options, settings).Run()
}

18
go.mod
View File

@ -1,13 +1,12 @@
module github.com/thegeeklab/drone-github-comment
module github.com/thegeeklab/wp-github-comment
go 1.20
require (
github.com/google/go-github/v53 v53.2.0
github.com/joho/godotenv v1.5.1
github.com/sirupsen/logrus v1.9.3
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4
github.com/urfave/cli/v2 v2.25.5
github.com/rs/zerolog v1.30.0
github.com/thegeeklab/wp-plugin-go v0.3.1
github.com/urfave/cli/v2 v2.25.7
golang.org/x/oauth2 v0.10.0
)
@ -17,11 +16,14 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)

46
go.sum
View File

@ -4,11 +4,10 @@ github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
@ -22,38 +21,40 @@ github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c=
github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4 h1:Quzrike/xRAR0izxQ0d+ocJyIUm4h1497Oyo9grcRzg=
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4/go.mod h1:qWVUZCmwL0Ntwa/hvyqM03EeIr1ReBR2XJsmIc7MGus=
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
github.com/thegeeklab/wp-plugin-go v0.3.1 h1:hbtP8NuwsVTJL7fFBaVebhhJC4TcSy6tFY1I5ydqzU0=
github.com/thegeeklab/wp-plugin-go v0.3.1/go.mod h1:7PWAZiTnZ2fAvjsedopQJ6w873KuSxUWsAml1Yib8a0=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
golang.org/x/oauth2 v0.10.0 h1:zHCpF2Khkwy4mMB4bv0U37YtJdTGW8jI0glAApi0Kh8=
golang.org/x/oauth2 v0.10.0/go.mod h1:kTpgurOux7LqtuxjuyZa4Gj2gdezIt/jQtGnNFfypQI=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
@ -66,6 +67,3 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

View File

@ -8,7 +8,6 @@ import (
"github.com/google/go-github/v53/github"
)
// Release holds ties the drone env data and github client together.
type commentClient struct {
Message string
Update bool

View File

@ -9,57 +9,60 @@ import (
"strings"
"github.com/google/go-github/v53/github"
"github.com/sirupsen/logrus"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
"golang.org/x/oauth2"
)
// Settings for the Plugin.
type Settings struct {
BaseURL string
IssueNum int
Key string
Message string
Update bool
APIKey string
SkipMissing bool
IsFile bool
baseURL *url.URL
}
var ErrPluginEventNotSupported = errors.New("event not supported")
// Execute provides the implementation of the plugin.
//
//nolint:revive
func (p *Plugin) run(ctx context.Context, cCtx *cli.Context) error {
if err := p.Validate(); err != nil {
return fmt.Errorf("validation failed: %w", err)
}
//nolint:contextcheck
if err := p.Execute(); err != nil {
return fmt.Errorf("execution failed: %w", err)
}
return nil
}
// Validate handles the settings validation of the plugin.
func (p *Plugin) Validate() error {
var err error
if p.pipeline.Build.Event != "pull_request" {
return fmt.Errorf("%w: %s", ErrPluginEventNotSupported, p.pipeline.Build.Event)
if p.Metadata.Pipeline.Event != "pull_request" {
return fmt.Errorf("%w: %s", ErrPluginEventNotSupported, p.Metadata.Pipeline.Event)
}
if p.settings.Message != "" {
if p.settings.Message, p.settings.IsFile, err = readStringOrFile(p.settings.Message); err != nil {
return fmt.Errorf("error while reading %s: %w", p.settings.Message, err)
if p.Settings.Message != "" {
if p.Settings.Message, p.Settings.IsFile, err = readStringOrFile(p.Settings.Message); err != nil {
return fmt.Errorf("error while reading %s: %w", p.Settings.Message, err)
}
}
if !strings.HasSuffix(p.settings.BaseURL, "/") {
p.settings.BaseURL += "/"
if !strings.HasSuffix(p.Settings.BaseURL, "/") {
p.Settings.BaseURL += "/"
}
p.settings.baseURL, err = url.Parse(p.settings.BaseURL)
p.Settings.baseURL, err = url.Parse(p.Settings.BaseURL)
if err != nil {
return fmt.Errorf("failed to parse base url: %w", err)
}
if p.settings.Key == "" {
key := fmt.Sprintf("%s/%s/%d", p.pipeline.Repo.Owner, p.pipeline.Repo.Name, p.settings.IssueNum)
if p.Settings.Key == "" {
key := fmt.Sprintf("%s/%s/%d", p.Metadata.Repository.Owner, p.Metadata.Repository.Name, p.Settings.IssueNum)
hash := sha256.Sum256([]byte(key))
p.settings.Key = fmt.Sprintf("%x", hash)
p.Settings.Key = fmt.Sprintf("%x", hash)
}
if p.settings.Key, _, err = readStringOrFile(p.settings.Key); err != nil {
return fmt.Errorf("error while reading %s: %w", p.settings.Key, err)
if p.Settings.Key, _, err = readStringOrFile(p.Settings.Key); err != nil {
return fmt.Errorf("error while reading %s: %w", p.Settings.Key, err)
}
return nil
@ -67,32 +70,33 @@ func (p *Plugin) Validate() error {
// Execute provides the implementation of the plugin.
func (p *Plugin) Execute() error {
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: p.settings.APIKey})
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: p.Settings.APIKey})
tc := oauth2.NewClient(
context.WithValue(context.Background(), oauth2.HTTPClient, p.network.Client),
context.WithValue(p.Network.Context, oauth2.HTTPClient, p.Network.Client),
ts,
)
client := github.NewClient(tc)
client.BaseURL = p.settings.baseURL
client.BaseURL = p.Settings.baseURL
commentClient := commentClient{
Client: client,
Repo: p.pipeline.Repo.Name,
Owner: p.pipeline.Repo.Owner,
Message: p.settings.Message,
Update: p.settings.Update,
Key: p.settings.Key,
IssueNum: p.pipeline.Build.PullRequest,
Repo: p.Metadata.Repository.Name,
Owner: p.Metadata.Repository.Owner,
Message: p.Settings.Message,
Update: p.Settings.Update,
Key: p.Settings.Key,
IssueNum: p.Metadata.Curr.PullRequest,
}
if p.settings.SkipMissing && !p.settings.IsFile {
logrus.Infof("comment skipped: 'message' is not a valid path or file does not exist while 'skip-missing' is enabled")
if p.Settings.SkipMissing && !p.Settings.IsFile {
log.Info().
Msg("comment skipped: 'message' is not a valid path or file does not exist while 'skip-missing' is enabled")
return nil
}
err := commentClient.issueComment(p.network.Context)
err := commentClient.issueComment(p.Network.Context)
if err != nil {
return fmt.Errorf("failed to create or update comment: %w", err)
}

View File

@ -1,21 +1,38 @@
package plugin
import (
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
"net/url"
wp "github.com/thegeeklab/wp-plugin-go/plugin"
)
// Plugin implements drone.Plugin to provide the plugin implementation.
// Plugin implements provide the plugin implementation.
type Plugin struct {
settings Settings
pipeline drone.Pipeline
network drone.Network
*wp.Plugin
Settings *Settings
}
// New initializes a plugin from the given Settings, Pipeline, and Network.
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) *Plugin {
return &Plugin{
settings: settings,
pipeline: pipeline,
network: network,
}
// Settings for the Plugin.
type Settings struct {
BaseURL string
IssueNum int
Key string
Message string
Update bool
APIKey string
SkipMissing bool
IsFile bool
baseURL *url.URL
}
func New(options wp.Options, settings *Settings) *Plugin {
p := &Plugin{}
options.Execute = p.run
p.Plugin = wp.New(options)
p.Settings = settings
return p
}