mirror of
https://github.com/thegeeklab/wp-github-comment.git
synced 2024-06-02 18:39:39 +02:00
Compare commits
98 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
98836fcb37 | ||
|
ade88cd306 | ||
|
9d20be9b37 | ||
|
636bc9ef4a | ||
3dfa592e96 | |||
|
a47fc5926c | ||
|
bc436f2940 | ||
23ed67963d | |||
96d603d111 | |||
|
6ddf49beb4 | ||
07d0b5405b | |||
|
b0333e8700 | ||
caafe6c2cf | |||
4138e06711 | |||
|
8ce857b9f9 | ||
|
14441d18c4 | ||
|
495b0aa272 | ||
|
87d4a691d6 | ||
|
97608ceb68 | ||
|
5c2c1e2fc6 | ||
|
728c0c7c5f | ||
|
72f7226872 | ||
|
dbff861000 | ||
|
5df7056ddc | ||
|
6dcf31ac98 | ||
|
79d21f32d5 | ||
|
2428e80890 | ||
|
c458a6306b | ||
|
e97f4335f4 | ||
abc57db69a | |||
|
568738a12a | ||
|
9b53f9a7c1 | ||
|
9c5c91a665 | ||
|
3a0a9261f1 | ||
|
658fb631b0 | ||
|
0d2addd0f9 | ||
ea72a8a7a4 | |||
cf7cda3da8 | |||
|
a6af05c8a4 | ||
|
a7cc02bd42 | ||
|
e4ebab49f2 | ||
|
1403a0ae1f | ||
07aff0af29 | |||
9288674b9e | |||
95e98a1c8b | |||
|
d6476cc16c | ||
|
a57c303b61 | ||
|
3b7a307713 | ||
|
39f399305b | ||
|
85f7b37c99 | ||
|
6ea798c89c | ||
|
89e8773282 | ||
|
714d84b7f6 | ||
|
fdc4447885 | ||
|
8f762c962a | ||
|
778e29350f | ||
|
c7f4007f85 | ||
ab048c2694 | |||
794b54d19d | |||
4e89e96c60 | |||
|
5b7f51cb33 | ||
|
b7e6baf2b3 | ||
866147aa8b | |||
|
469db2f48c | ||
|
67510cbfcb | ||
|
ec3f09db9f | ||
|
5be12f3e0a | ||
|
00986f6e0c | ||
|
4bda038ff7 | ||
b10c877c4e | |||
|
b48a8b3a8f | ||
|
da6781b749 | ||
|
0aad7b4d9d | ||
|
32eb7d541e | ||
|
cffbbcd475 | ||
3b814cd74a | |||
|
74cf96d40e | ||
|
9ecd5402e4 | ||
b75c9d8063 | |||
|
c8eecec6f7 | ||
|
3ab85def72 | ||
|
59c9375466 | ||
|
eda2e78f7f | ||
|
553d4b721a | ||
|
2a56b76594 | ||
|
eb4e8990fb | ||
|
7bade7fd6c | ||
|
edbcc24f81 | ||
a162fdb98b | |||
|
6b251b00b7 | ||
|
99e699c84b | ||
|
4bc7b07603 | ||
|
fe99566447 | ||
|
85b98f8a4b | ||
|
2074033a07 | ||
cf6577d2c6 | |||
48ad6c6bc5 | |||
|
64c8e95fb3 |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,6 +1,7 @@
|
|||
/dist
|
||||
/release
|
||||
/wp-github-comment*
|
||||
docs/data/data-raw.yaml
|
||||
|
||||
coverage.out
|
||||
CHANGELOG.md
|
||||
|
|
|
@ -35,7 +35,7 @@ release-notes:
|
|||
- name: Documentation
|
||||
commit-types: [docs]
|
||||
section-type: commits
|
||||
- name: Breaking Changes
|
||||
- name: BREAKING CHANGES
|
||||
section-type: breaking-changes
|
||||
|
||||
commit-message:
|
||||
|
|
|
@ -23,7 +23,6 @@ linters:
|
|||
- errchkjson
|
||||
- errname
|
||||
- errorlint
|
||||
- execinquery
|
||||
- exhaustive
|
||||
- exportloopref
|
||||
- forcetypeassert
|
||||
|
@ -37,12 +36,12 @@ linters:
|
|||
- gocyclo
|
||||
- godot
|
||||
- godox
|
||||
- goerr113
|
||||
- err113
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goheader
|
||||
- goimports
|
||||
- gomnd
|
||||
- mnd
|
||||
- gomoddirectives
|
||||
- gomodguard
|
||||
- goprintffuncname
|
||||
|
@ -86,6 +85,7 @@ linters:
|
|||
# - wastedassign
|
||||
- whitespace
|
||||
- wsl
|
||||
- zerologlint
|
||||
fast: false
|
||||
|
||||
run:
|
||||
|
@ -94,4 +94,3 @@ run:
|
|||
linters-settings:
|
||||
gofumpt:
|
||||
extra-rules: true
|
||||
lang-version: "1.21"
|
||||
|
|
1
.lycheeignore
Normal file
1
.lycheeignore
Normal file
|
@ -0,0 +1 @@
|
|||
https://hub.docker.com/r/thegeeklab/*
|
6
.mockery.yaml
Normal file
6
.mockery.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
all: True
|
||||
dir: "{{.PackageName}}/mocks"
|
||||
outpkg: "mocks"
|
||||
packages:
|
||||
github.com/thegeeklab/wp-github-comment/github:
|
|
@ -6,8 +6,8 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
dryrun:
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:1
|
||||
- name: dryrun
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||
settings:
|
||||
containerfile: Containerfile.multiarch
|
||||
dry_run: true
|
||||
|
@ -19,9 +19,9 @@ steps:
|
|||
when:
|
||||
- event: [pull_request]
|
||||
|
||||
publish-dockerhub:
|
||||
- name: publish-dockerhub
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||
group: container
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:1
|
||||
settings:
|
||||
auto_tag: true
|
||||
containerfile: Containerfile.multiarch
|
||||
|
@ -40,9 +40,9 @@ steps:
|
|||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
publish-quay:
|
||||
- name: publish-quay
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:4
|
||||
group: container
|
||||
image: quay.io/thegeeklab/wp-docker-buildx:1
|
||||
settings:
|
||||
auto_tag: true
|
||||
containerfile: Containerfile.multiarch
|
||||
|
|
|
@ -6,26 +6,25 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
build:
|
||||
image: docker.io/techknowlogick/xgo:go-1.21.x
|
||||
- name: build
|
||||
image: docker.io/techknowlogick/xgo:go-1.22.x
|
||||
commands:
|
||||
- ln -s $(pwd) /source
|
||||
- make release
|
||||
|
||||
executable:
|
||||
- name: executable
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
commands:
|
||||
- $(find dist/ -executable -type f -iname ${CI_REPO_NAME}-linux-amd64) --help
|
||||
|
||||
changelog:
|
||||
- name: changelog
|
||||
image: quay.io/thegeeklab/git-sv
|
||||
commands:
|
||||
- git fetch --depth=2147483647
|
||||
- git sv current-version
|
||||
- git sv release-notes -t ${CI_COMMIT_TAG:-next} -o CHANGELOG.md
|
||||
- cat CHANGELOG.md
|
||||
|
||||
publish-github:
|
||||
- name: publish-github
|
||||
image: docker.io/plugins/github-release
|
||||
settings:
|
||||
api_key:
|
||||
|
@ -36,7 +35,7 @@ steps:
|
|||
overwrite: true
|
||||
title: ${CI_COMMIT_TAG}
|
||||
when:
|
||||
- event: [tag]
|
||||
- event: [tag]
|
||||
|
||||
depends_on:
|
||||
- test
|
||||
|
|
|
@ -6,26 +6,27 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
markdownlint:
|
||||
- name: markdownlint
|
||||
image: quay.io/thegeeklab/markdownlint-cli
|
||||
group: test
|
||||
commands:
|
||||
- markdownlint 'README.md' 'CONTRIBUTING.md'
|
||||
|
||||
spellcheck:
|
||||
- name: spellcheck
|
||||
image: quay.io/thegeeklab/alpine-tools
|
||||
group: test
|
||||
commands:
|
||||
- spellchecker --files '_docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
|
||||
- spellchecker --files 'docs/**/*.md' 'README.md' 'CONTRIBUTING.md' -d .dictionary -p spell indefinite-article syntax-urls
|
||||
environment:
|
||||
FORCE_COLOR: "true"
|
||||
NPM_CONFIG_LOGLEVEL: "error"
|
||||
|
||||
link-validation:
|
||||
- name: link-validation
|
||||
image: docker.io/lycheeverse/lychee
|
||||
group: test
|
||||
commands:
|
||||
- lychee --no-progress --format detailed _docs/content README.md
|
||||
- lychee --no-progress --format detailed docs/content README.md
|
||||
|
||||
publish:
|
||||
- name: publish
|
||||
image: quay.io/thegeeklab/wp-git-action
|
||||
settings:
|
||||
action:
|
||||
|
@ -36,19 +37,20 @@ steps:
|
|||
message: "[skip ci] auto-update documentation"
|
||||
netrc_password:
|
||||
from_secret: github_token
|
||||
pages_directory: _docs/
|
||||
pages_directory: docs/
|
||||
when:
|
||||
- event: [push, manual]
|
||||
branch:
|
||||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
status: [success, failure]
|
||||
|
||||
pushrm-dockerhub:
|
||||
- name: pushrm-dockerhub
|
||||
image: docker.io/chko/docker-pushrm:1
|
||||
secrets:
|
||||
- source: docker_password
|
||||
target: DOCKER_PASS
|
||||
target: DOCKER_PASS
|
||||
- source: docker_username
|
||||
target: DOCKER_USER
|
||||
target: DOCKER_USER
|
||||
environment:
|
||||
PUSHRM_FILE: README.md
|
||||
PUSHRM_SHORT: Woodpecker CI plugin to add comments to GitHub Issues and Pull Requests
|
||||
|
@ -59,7 +61,7 @@ steps:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
status: [success]
|
||||
|
||||
pushrm-quay:
|
||||
- name: pushrm-quay
|
||||
image: docker.io/chko/docker-pushrm:1
|
||||
secrets:
|
||||
- source: quay_token
|
||||
|
|
|
@ -8,7 +8,7 @@ when:
|
|||
runs_on: [success, failure]
|
||||
|
||||
steps:
|
||||
matrix:
|
||||
- name: matrix
|
||||
image: quay.io/thegeeklab/wp-matrix
|
||||
settings:
|
||||
homeserver:
|
||||
|
|
|
@ -6,12 +6,12 @@ when:
|
|||
- ${CI_REPO_DEFAULT_BRANCH}
|
||||
|
||||
steps:
|
||||
lint:
|
||||
image: docker.io/library/golang:1.21
|
||||
- name: lint
|
||||
image: docker.io/library/golang:1.22
|
||||
commands:
|
||||
- make lint
|
||||
|
||||
test:
|
||||
image: docker.io/library/golang:1.21
|
||||
- name: test
|
||||
image: docker.io/library/golang:1.22
|
||||
commands:
|
||||
- make test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM --platform=$BUILDPLATFORM golang:1.21@sha256:24a09375a6216764a3eda6a25490a88ac178b5fcb9511d59d0da5ebf9e496474 as build
|
||||
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.22@sha256:f43c6f049f04cbbaeb28f0aad3eea15274a7d0a7899a617d0037aec48d7ab010 as build
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
|
@ -8,7 +8,7 @@ WORKDIR /src
|
|||
|
||||
RUN make build
|
||||
|
||||
FROM alpine:3.18@sha256:eece025e432126ce23f223450a0326fbebde39cdf496a85d8c016293fc851978
|
||||
FROM docker.io/library/alpine:3.20@sha256:77726ef6b57ddf65bb551896826ec38bc3e53f75cdde31354fbffb4f25238ebd
|
||||
|
||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
||||
|
|
15
Makefile
15
Makefile
|
@ -1,7 +1,7 @@
|
|||
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
||||
GOFUMPT_PACKAGE_VERSION := v0.5.0
|
||||
GOFUMPT_PACKAGE_VERSION := v0.6.0
|
||||
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.54.2
|
||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.59.0
|
||||
|
||||
EXECUTABLE := wp-github-comment
|
||||
|
||||
|
@ -17,9 +17,10 @@ SOURCES ?= $(shell find . -name "*.go" -type f)
|
|||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
||||
GOTESTSUM_PACKAGE ?= gotest.tools/gotestsum@latest
|
||||
MOCKERY_PACKAGE ?= github.com/vektra/mockery/v2@latest
|
||||
|
||||
GENERATE ?=
|
||||
XGO_VERSION := go-1.21.x
|
||||
XGO_VERSION := go-1.22.x
|
||||
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
|
||||
|
||||
TARGETOS ?= linux
|
||||
|
@ -64,11 +65,12 @@ lint: golangci-lint
|
|||
|
||||
.PHONY: generate
|
||||
generate:
|
||||
$(GO) generate $(GENERATE)
|
||||
$(GO) generate $(PACKAGES)
|
||||
$(GO) run $(MOCKERY_PACKAGE)
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
$(GO) test -v -coverprofile coverage.out $(PACKAGES)
|
||||
$(GO) run $(GOTESTSUM_PACKAGE) --no-color=false -- -coverprofile=coverage.out $(PACKAGES)
|
||||
|
||||
.PHONY: build
|
||||
build: $(DIST)/$(EXECUTABLE)
|
||||
|
@ -99,3 +101,4 @@ deps:
|
|||
$(GO) install $(GOFUMPT_PACKAGE)
|
||||
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
||||
$(GO) install $(XGO_PACKAGE)
|
||||
$(GO) install $(GOTESTSUM_PACKAGE)
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
---
|
||||
properties:
|
||||
- name: api_key
|
||||
description: Personal Access token to access the GitHub API.
|
||||
type: string
|
||||
required: true
|
||||
|
||||
- name: base_url
|
||||
description: API URL. Only need to be changed for GitHub enterprise in most cases
|
||||
defaultValue: https://api.github.com
|
||||
type: string
|
||||
required: false
|
||||
|
||||
- name: key
|
||||
description: Unique identifier to assign to a comment. The identifier is used to update an existing comment.
|
||||
type: string
|
||||
required: false
|
||||
|
||||
- name: message
|
||||
description: Path to file or string that contains the comment text.
|
||||
type: string
|
||||
required: true
|
||||
|
||||
- name: update
|
||||
description: Enables update of an existing comment that matches the key.
|
||||
defaultValue: false
|
||||
type: bool
|
||||
required: false
|
||||
|
||||
- name: skip_missing
|
||||
description: Skips comment creation if the given message file does not exist
|
||||
defaultValue: false
|
||||
type: bool
|
||||
required: false
|
|
@ -1,59 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/thegeeklab/wp-github-comment/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
||||
func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "api-key",
|
||||
EnvVars: []string{"PLUGIN_API_KEY", "GITHUB_COMMENT_API_KEY"},
|
||||
Usage: "personal access token access github api",
|
||||
Destination: &settings.APIKey,
|
||||
Category: category,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "base-url",
|
||||
EnvVars: []string{"PLUGIN_BASE_URL", "GITHUB_COMMENT_BASE_URL"},
|
||||
Usage: "api url",
|
||||
Value: "https://api.github.com/",
|
||||
Destination: &settings.BaseURL,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "key",
|
||||
EnvVars: []string{"PLUGIN_KEY", "GITHUB_COMMENT_KEY"},
|
||||
Usage: "unique identifier to assign to comment",
|
||||
Destination: &settings.Key,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "message",
|
||||
EnvVars: []string{"PLUGIN_MESSAGE", "GITHUB_COMMENT_MESSAGE"},
|
||||
Usage: "file or string that holds the comment text",
|
||||
Destination: &settings.Message,
|
||||
Category: category,
|
||||
Required: true,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "update",
|
||||
EnvVars: []string{"PLUGIN_UPDATE", "GITHUB_COMMENT_UPDATE"},
|
||||
Usage: "update existing comment that matches the key",
|
||||
Value: false,
|
||||
Destination: &settings.Update,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-missing",
|
||||
EnvVars: []string{"PLUGIN_SKIP_MISSING", "GITHUB_COMMENT_SKIP_MISSING"},
|
||||
Usage: "skip creation of comment if message file does not exist",
|
||||
Value: false,
|
||||
Destination: &settings.SkipMissing,
|
||||
Category: category,
|
||||
},
|
||||
}
|
||||
}
|
|
@ -1,11 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/thegeeklab/wp-github-comment/plugin"
|
||||
|
||||
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
||||
)
|
||||
|
||||
//nolint:gochecknoglobals
|
||||
|
@ -15,14 +11,5 @@ var (
|
|||
)
|
||||
|
||||
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()
|
||||
plugin.New(nil, BuildVersion, BuildDate).Run()
|
||||
}
|
||||
|
|
|
@ -29,14 +29,11 @@ Only pull request events are supported by this plugin. Running the plugin on oth
|
|||
{{< /hint >}}
|
||||
|
||||
```YAML
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: pr-comment
|
||||
image: thegeeklab/wp-github-comment
|
||||
image: quay.io/thegeeklab/wp-github-comment
|
||||
settings:
|
||||
api_key: ghp_3LbMg9Kncpdkhjp3bh3dMnKNXLjVMTsXk4sM
|
||||
api_key: ghp_randomstring
|
||||
message: "CI run completed successfully"
|
||||
update: true
|
||||
```
|
||||
|
@ -71,7 +68,7 @@ docker run --rm \
|
|||
-e CI_REPO_OWNER=octocat \
|
||||
-e CI_REPO_NAME=foo \
|
||||
-e CI_COMMIT_PULL_REQUEST=1
|
||||
-e PLUGIN_API_KEY=abc123 \
|
||||
-e PLUGIN_API_KEY=ghp_randomstring \
|
||||
-e PLUGIN_MESSAGE="Demo comment" \
|
||||
-v $(pwd):/build:z \
|
||||
-w /build \
|
58
docs/data/data.yaml
Normal file
58
docs/data/data.yaml
Normal file
|
@ -0,0 +1,58 @@
|
|||
---
|
||||
properties:
|
||||
- name: api_key
|
||||
description: |
|
||||
Personal access token to access the GitHub API.
|
||||
type: string
|
||||
required: true
|
||||
|
||||
- name: base_url
|
||||
description: |
|
||||
Api url.
|
||||
|
||||
Only need to be changed for GitHub enterprise in most cases.
|
||||
type: string
|
||||
defaultValue: "https://api.github.com/"
|
||||
required: false
|
||||
|
||||
- name: insecure_skip_verify
|
||||
description: |
|
||||
Skip SSL verification.
|
||||
type: bool
|
||||
defaultValue: false
|
||||
required: false
|
||||
|
||||
- name: key
|
||||
description: |
|
||||
Unique identifier to assign to a comment.
|
||||
|
||||
The identifier is used to update an existing comment.
|
||||
type: string
|
||||
required: false
|
||||
|
||||
- name: log_level
|
||||
description: |
|
||||
Plugin log level.
|
||||
type: string
|
||||
defaultValue: "info"
|
||||
required: false
|
||||
|
||||
- name: message
|
||||
description: |
|
||||
Path to file or string that contains the comment text.
|
||||
type: string
|
||||
required: true
|
||||
|
||||
- name: skip_missing
|
||||
description: |
|
||||
Skip comment creation if the given message file does not exist.
|
||||
type: bool
|
||||
defaultValue: false
|
||||
required: false
|
||||
|
||||
- name: update
|
||||
description: |
|
||||
Enable update of an existing comment that matches the key.
|
||||
type: bool
|
||||
defaultValue: false
|
||||
required: false
|
41
github/api.go
Normal file
41
github/api.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/go-github/v62/github"
|
||||
)
|
||||
|
||||
// APIClient is an interface that wraps the GitHub API client.
|
||||
//
|
||||
//nolint:lll
|
||||
type IssueService interface {
|
||||
CreateComment(ctx context.Context, owner, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
|
||||
EditComment(ctx context.Context, owner, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error)
|
||||
ListComments(ctx context.Context, owner, repo string, number int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)
|
||||
}
|
||||
|
||||
type IssueServiceImpl struct {
|
||||
client *github.Client
|
||||
}
|
||||
|
||||
// CreateComment wraps the CreateComment method of the github.IssuesService.
|
||||
//
|
||||
//nolint:lll
|
||||
func (s *IssueServiceImpl) CreateComment(ctx context.Context, owner, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) {
|
||||
return s.client.Issues.CreateComment(ctx, owner, repo, number, comment)
|
||||
}
|
||||
|
||||
// EditComment wraps the EditComment method of the github.IssuesService.
|
||||
//
|
||||
//nolint:lll
|
||||
func (s *IssueServiceImpl) EditComment(ctx context.Context, owner, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) {
|
||||
return s.client.Issues.EditComment(ctx, owner, repo, commentID, comment)
|
||||
}
|
||||
|
||||
// ListComments wraps the ListComments method of the github.IssuesService.
|
||||
//
|
||||
//nolint:lll
|
||||
func (s *IssueServiceImpl) ListComments(ctx context.Context, owner, repo string, number int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error) {
|
||||
return s.client.Issues.ListComments(ctx, owner, repo, number, opts)
|
||||
}
|
117
github/github.go
Normal file
117
github/github.go
Normal file
|
@ -0,0 +1,117 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v62/github"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
var ErrCommentNotFound = errors.New("comment not found")
|
||||
|
||||
type Client struct {
|
||||
client *github.Client
|
||||
Issue *Issue
|
||||
}
|
||||
|
||||
type Issue struct {
|
||||
client IssueService
|
||||
Opt IssueOptions
|
||||
}
|
||||
|
||||
type IssueOptions struct {
|
||||
Number int
|
||||
Message string
|
||||
Key string
|
||||
Repo string
|
||||
Owner string
|
||||
Update bool
|
||||
}
|
||||
|
||||
// NewGitHubClient creates a new GitHubClient instance that wraps the provided GitHub API client.
|
||||
// The GitHubClient provides a higher-level interface for interacting with the GitHub API,
|
||||
// including methods for managing GitHub issues.
|
||||
func NewClient(ctx context.Context, url *url.URL, token string, client *http.Client) *Client {
|
||||
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
|
||||
tc := oauth2.NewClient(
|
||||
context.WithValue(ctx, oauth2.HTTPClient, client),
|
||||
ts,
|
||||
)
|
||||
|
||||
c := github.NewClient(tc)
|
||||
c.BaseURL = url
|
||||
|
||||
return &Client{
|
||||
client: c,
|
||||
Issue: &Issue{
|
||||
client: &IssueServiceImpl{client: c},
|
||||
Opt: IssueOptions{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// AddComment adds a new comment or updates an existing comment on a GitHub issue.
|
||||
// If the Update field is true, it will append a unique identifier to the comment
|
||||
// body and attempt to find and update the existing comment with that identifier.
|
||||
// Otherwise, it will create a new comment on the issue.
|
||||
func (i *Issue) AddComment(ctx context.Context) (*github.IssueComment, error) {
|
||||
issueComment := &github.IssueComment{
|
||||
Body: &i.Opt.Message,
|
||||
}
|
||||
|
||||
if i.Opt.Update {
|
||||
// Append plugin comment ID to comment message so we can search for it later
|
||||
*issueComment.Body = fmt.Sprintf("%s\n<!-- id: %s -->\n", i.Opt.Message, i.Opt.Key)
|
||||
|
||||
comment, err := i.FindComment(ctx)
|
||||
if err != nil && !errors.Is(err, ErrCommentNotFound) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if comment != nil {
|
||||
comment, _, err = i.client.EditComment(ctx, i.Opt.Owner, i.Opt.Repo, *comment.ID, issueComment)
|
||||
|
||||
return comment, err
|
||||
}
|
||||
}
|
||||
|
||||
comment, _, err := i.client.CreateComment(ctx, i.Opt.Owner, i.Opt.Repo, i.Opt.Number, issueComment)
|
||||
|
||||
return comment, err
|
||||
}
|
||||
|
||||
// FindComment returns the GitHub issue comment that contains the specified key, or nil if no such comment exists.
|
||||
// It retrieves all comments on the issue and searches for one that contains the specified key in the comment body.
|
||||
func (i *Issue) FindComment(ctx context.Context) (*github.IssueComment, error) {
|
||||
var allComments []*github.IssueComment
|
||||
|
||||
opts := &github.IssueListCommentsOptions{}
|
||||
|
||||
for {
|
||||
comments, resp, err := i.client.ListComments(ctx, i.Opt.Owner, i.Opt.Repo, i.Opt.Number, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allComments = append(allComments, comments...)
|
||||
|
||||
if resp == nil || resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
opts.Page = resp.NextPage
|
||||
}
|
||||
|
||||
for _, comment := range allComments {
|
||||
if strings.Contains(*comment.Body, fmt.Sprintf("<!-- id: %s -->", i.Opt.Key)) {
|
||||
return comment, nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("%w: failed to find comment with key %s", ErrCommentNotFound, i.Opt.Key)
|
||||
}
|
212
github/github_test.go
Normal file
212
github/github_test.go
Normal file
|
@ -0,0 +1,212 @@
|
|||
package github
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-github/v62/github"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"github.com/thegeeklab/wp-github-comment/github/mocks"
|
||||
)
|
||||
|
||||
var ErrInternalServerError = errors.New("internal server error")
|
||||
|
||||
func TestGithubIssue_FindComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
issueOpt IssueOptions
|
||||
comments []*github.IssueComment
|
||||
want *github.IssueComment
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "no comments",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
},
|
||||
wantErr: ErrCommentNotFound,
|
||||
},
|
||||
{
|
||||
name: "comment found",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
},
|
||||
comments: []*github.IssueComment{
|
||||
{Body: github.String("<!-- id: test-key -->\ntest comment\n")},
|
||||
},
|
||||
want: &github.IssueComment{
|
||||
Body: github.String("<!-- id: test-key -->\ntest comment\n"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "comment not found",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
},
|
||||
comments: []*github.IssueComment{
|
||||
{Body: github.String("other comment")},
|
||||
},
|
||||
wantErr: ErrCommentNotFound,
|
||||
},
|
||||
{
|
||||
name: "multiple comments",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
},
|
||||
comments: []*github.IssueComment{
|
||||
{Body: github.String("other comment")},
|
||||
{Body: github.String("<!-- id: test-key -->\ntest comment\n")},
|
||||
{Body: github.String("another comment")},
|
||||
},
|
||||
want: &github.IssueComment{Body: github.String("<!-- id: test-key -->\ntest comment\n")},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockClient := mocks.NewMockIssueService(t)
|
||||
issue := &Issue{
|
||||
client: mockClient,
|
||||
Opt: tt.issueOpt,
|
||||
}
|
||||
|
||||
mockClient.
|
||||
On("ListComments", mock.Anything, tt.issueOpt.Owner, tt.issueOpt.Repo, mock.Anything, mock.Anything).
|
||||
Return(tt.comments, nil, nil)
|
||||
|
||||
got, err := issue.FindComment(context.Background())
|
||||
if tt.wantErr != nil {
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGithubIssue_AddComment(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
issueOpt IssueOptions
|
||||
comments []*github.IssueComment
|
||||
want *github.IssueComment
|
||||
wantErr error
|
||||
}{
|
||||
{
|
||||
name: "create new comment",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
Message: "test message",
|
||||
Update: false,
|
||||
},
|
||||
want: &github.IssueComment{
|
||||
Body: github.String("<!-- id: test-key -->\ntest message\n"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update existing comment",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
Message: "test message",
|
||||
Update: true,
|
||||
},
|
||||
comments: []*github.IssueComment{
|
||||
{ID: github.Int64(123), Body: github.String("<!-- id: test-key -->\ntest message\n")},
|
||||
},
|
||||
want: &github.IssueComment{
|
||||
Body: github.String("<!-- id: test-key -->\ntest message\n"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "update non-existing comment",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
Message: "test message",
|
||||
Update: true,
|
||||
},
|
||||
want: &github.IssueComment{
|
||||
Body: github.String("<!-- id: test-key -->\ntest message\n"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "create new comment with error",
|
||||
issueOpt: IssueOptions{
|
||||
Key: "test-key",
|
||||
Owner: "test-owner",
|
||||
Repo: "test-repo",
|
||||
Message: "test message",
|
||||
Update: false,
|
||||
},
|
||||
wantErr: ErrInternalServerError,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
mockClient := mocks.NewMockIssueService(t)
|
||||
issue := &Issue{
|
||||
client: mockClient,
|
||||
Opt: tt.issueOpt,
|
||||
}
|
||||
|
||||
if tt.issueOpt.Update {
|
||||
mockClient.
|
||||
On("ListComments", mock.Anything, tt.issueOpt.Owner, tt.issueOpt.Repo, mock.Anything, mock.Anything).
|
||||
Return(tt.comments, nil, nil)
|
||||
}
|
||||
|
||||
if tt.issueOpt.Update && tt.comments != nil {
|
||||
mockClient.
|
||||
On("EditComment", mock.Anything, tt.issueOpt.Owner, tt.issueOpt.Repo, mock.Anything, mock.Anything).
|
||||
Return(&github.IssueComment{
|
||||
Body: github.String(fmt.Sprintf("<!-- id: %s -->\n%s\n", tt.issueOpt.Key, tt.issueOpt.Message)),
|
||||
}, nil, nil)
|
||||
}
|
||||
|
||||
if tt.comments == nil {
|
||||
var comment *github.IssueComment
|
||||
if tt.wantErr == nil {
|
||||
comment = &github.IssueComment{
|
||||
Body: github.String(fmt.Sprintf("<!-- id: %s -->\n%s\n", tt.issueOpt.Key, tt.issueOpt.Message)),
|
||||
}
|
||||
}
|
||||
|
||||
mockClient.
|
||||
On("CreateComment", mock.Anything, tt.issueOpt.Owner, tt.issueOpt.Repo, mock.Anything, mock.Anything).
|
||||
Return(comment, nil, tt.wantErr)
|
||||
}
|
||||
|
||||
got, err := issue.AddComment(context.Background())
|
||||
if tt.wantErr != nil {
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
250
github/mocks/mock_IssueService.go
Normal file
250
github/mocks/mock_IssueService.go
Normal file
|
@ -0,0 +1,250 @@
|
|||
// Code generated by mockery v2.43.0. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
github "github.com/google/go-github/v62/github"
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// MockIssueService is an autogenerated mock type for the IssueService type
|
||||
type MockIssueService struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type MockIssueService_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *MockIssueService) EXPECT() *MockIssueService_Expecter {
|
||||
return &MockIssueService_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// CreateComment provides a mock function with given fields: ctx, owner, repo, number, comment
|
||||
func (_m *MockIssueService) CreateComment(ctx context.Context, owner string, repo string, number int, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) {
|
||||
ret := _m.Called(ctx, owner, repo, number, comment)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CreateComment")
|
||||
}
|
||||
|
||||
var r0 *github.IssueComment
|
||||
var r1 *github.Response
|
||||
var r2 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int, *github.IssueComment) (*github.IssueComment, *github.Response, error)); ok {
|
||||
return rf(ctx, owner, repo, number, comment)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int, *github.IssueComment) *github.IssueComment); ok {
|
||||
r0 = rf(ctx, owner, repo, number, comment)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*github.IssueComment)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, string, int, *github.IssueComment) *github.Response); ok {
|
||||
r1 = rf(ctx, owner, repo, number, comment)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*github.Response)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(2).(func(context.Context, string, string, int, *github.IssueComment) error); ok {
|
||||
r2 = rf(ctx, owner, repo, number, comment)
|
||||
} else {
|
||||
r2 = ret.Error(2)
|
||||
}
|
||||
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// MockIssueService_CreateComment_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CreateComment'
|
||||
type MockIssueService_CreateComment_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// CreateComment is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - owner string
|
||||
// - repo string
|
||||
// - number int
|
||||
// - comment *github.IssueComment
|
||||
func (_e *MockIssueService_Expecter) CreateComment(ctx interface{}, owner interface{}, repo interface{}, number interface{}, comment interface{}) *MockIssueService_CreateComment_Call {
|
||||
return &MockIssueService_CreateComment_Call{Call: _e.mock.On("CreateComment", ctx, owner, repo, number, comment)}
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_CreateComment_Call) Run(run func(ctx context.Context, owner string, repo string, number int, comment *github.IssueComment)) *MockIssueService_CreateComment_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int), args[4].(*github.IssueComment))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_CreateComment_Call) Return(_a0 *github.IssueComment, _a1 *github.Response, _a2 error) *MockIssueService_CreateComment_Call {
|
||||
_c.Call.Return(_a0, _a1, _a2)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_CreateComment_Call) RunAndReturn(run func(context.Context, string, string, int, *github.IssueComment) (*github.IssueComment, *github.Response, error)) *MockIssueService_CreateComment_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// EditComment provides a mock function with given fields: ctx, owner, repo, commentID, comment
|
||||
func (_m *MockIssueService) EditComment(ctx context.Context, owner string, repo string, commentID int64, comment *github.IssueComment) (*github.IssueComment, *github.Response, error) {
|
||||
ret := _m.Called(ctx, owner, repo, commentID, comment)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for EditComment")
|
||||
}
|
||||
|
||||
var r0 *github.IssueComment
|
||||
var r1 *github.Response
|
||||
var r2 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int64, *github.IssueComment) (*github.IssueComment, *github.Response, error)); ok {
|
||||
return rf(ctx, owner, repo, commentID, comment)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int64, *github.IssueComment) *github.IssueComment); ok {
|
||||
r0 = rf(ctx, owner, repo, commentID, comment)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*github.IssueComment)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, string, int64, *github.IssueComment) *github.Response); ok {
|
||||
r1 = rf(ctx, owner, repo, commentID, comment)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*github.Response)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(2).(func(context.Context, string, string, int64, *github.IssueComment) error); ok {
|
||||
r2 = rf(ctx, owner, repo, commentID, comment)
|
||||
} else {
|
||||
r2 = ret.Error(2)
|
||||
}
|
||||
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// MockIssueService_EditComment_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'EditComment'
|
||||
type MockIssueService_EditComment_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// EditComment is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - owner string
|
||||
// - repo string
|
||||
// - commentID int64
|
||||
// - comment *github.IssueComment
|
||||
func (_e *MockIssueService_Expecter) EditComment(ctx interface{}, owner interface{}, repo interface{}, commentID interface{}, comment interface{}) *MockIssueService_EditComment_Call {
|
||||
return &MockIssueService_EditComment_Call{Call: _e.mock.On("EditComment", ctx, owner, repo, commentID, comment)}
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_EditComment_Call) Run(run func(ctx context.Context, owner string, repo string, commentID int64, comment *github.IssueComment)) *MockIssueService_EditComment_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int64), args[4].(*github.IssueComment))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_EditComment_Call) Return(_a0 *github.IssueComment, _a1 *github.Response, _a2 error) *MockIssueService_EditComment_Call {
|
||||
_c.Call.Return(_a0, _a1, _a2)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_EditComment_Call) RunAndReturn(run func(context.Context, string, string, int64, *github.IssueComment) (*github.IssueComment, *github.Response, error)) *MockIssueService_EditComment_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListComments provides a mock function with given fields: ctx, owner, repo, number, opts
|
||||
func (_m *MockIssueService) ListComments(ctx context.Context, owner string, repo string, number int, opts *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error) {
|
||||
ret := _m.Called(ctx, owner, repo, number, opts)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListComments")
|
||||
}
|
||||
|
||||
var r0 []*github.IssueComment
|
||||
var r1 *github.Response
|
||||
var r2 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int, *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)); ok {
|
||||
return rf(ctx, owner, repo, number, opts)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, string, string, int, *github.IssueListCommentsOptions) []*github.IssueComment); ok {
|
||||
r0 = rf(ctx, owner, repo, number, opts)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).([]*github.IssueComment)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, string, string, int, *github.IssueListCommentsOptions) *github.Response); ok {
|
||||
r1 = rf(ctx, owner, repo, number, opts)
|
||||
} else {
|
||||
if ret.Get(1) != nil {
|
||||
r1 = ret.Get(1).(*github.Response)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(2).(func(context.Context, string, string, int, *github.IssueListCommentsOptions) error); ok {
|
||||
r2 = rf(ctx, owner, repo, number, opts)
|
||||
} else {
|
||||
r2 = ret.Error(2)
|
||||
}
|
||||
|
||||
return r0, r1, r2
|
||||
}
|
||||
|
||||
// MockIssueService_ListComments_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListComments'
|
||||
type MockIssueService_ListComments_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListComments is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - owner string
|
||||
// - repo string
|
||||
// - number int
|
||||
// - opts *github.IssueListCommentsOptions
|
||||
func (_e *MockIssueService_Expecter) ListComments(ctx interface{}, owner interface{}, repo interface{}, number interface{}, opts interface{}) *MockIssueService_ListComments_Call {
|
||||
return &MockIssueService_ListComments_Call{Call: _e.mock.On("ListComments", ctx, owner, repo, number, opts)}
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_ListComments_Call) Run(run func(ctx context.Context, owner string, repo string, number int, opts *github.IssueListCommentsOptions)) *MockIssueService_ListComments_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
run(args[0].(context.Context), args[1].(string), args[2].(string), args[3].(int), args[4].(*github.IssueListCommentsOptions))
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_ListComments_Call) Return(_a0 []*github.IssueComment, _a1 *github.Response, _a2 error) *MockIssueService_ListComments_Call {
|
||||
_c.Call.Return(_a0, _a1, _a2)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *MockIssueService_ListComments_Call) RunAndReturn(run func(context.Context, string, string, int, *github.IssueListCommentsOptions) ([]*github.IssueComment, *github.Response, error)) *MockIssueService_ListComments_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewMockIssueService creates a new instance of MockIssueService. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewMockIssueService(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *MockIssueService {
|
||||
mock := &MockIssueService{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
39
go.mod
39
go.mod
|
@ -1,26 +1,39 @@
|
|||
module github.com/thegeeklab/wp-github-comment
|
||||
|
||||
go 1.21
|
||||
go 1.22
|
||||
|
||||
require (
|
||||
github.com/google/go-github/v56 v56.0.0
|
||||
github.com/rs/zerolog v1.31.0
|
||||
github.com/thegeeklab/wp-plugin-go v1.0.2
|
||||
github.com/urfave/cli/v2 v2.25.7
|
||||
golang.org/x/oauth2 v0.13.0
|
||||
github.com/google/go-github/v62 v62.0.0
|
||||
github.com/rs/zerolog v1.33.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2
|
||||
github.com/urfave/cli/v2 v2.27.2
|
||||
golang.org/x/oauth2 v0.20.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/Masterminds/semver/v3 v3.2.1 // indirect
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/uuid v1.1.1 // indirect
|
||||
github.com/huandu/xstrings v1.3.3 // indirect
|
||||
github.com/imdario/mergo v0.3.11 // indirect
|
||||
github.com/joho/godotenv v1.5.1 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/mitchellh/copystructure v1.0.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
github.com/shopspring/decimal v1.2.0 // indirect
|
||||
github.com/spf13/cast v1.3.1 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
|
||||
golang.org/x/crypto v0.23.0 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
119
go.sum
119
go.sum
|
@ -1,19 +1,30 @@
|
|||
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
|
||||
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
|
||||
github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
|
||||
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA=
|
||||
github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM=
|
||||
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/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/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=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v56 v56.0.0 h1:TysL7dMa/r7wsQi44BjqlwaHvwlFlqkK8CtBWCX3gb4=
|
||||
github.com/google/go-github/v56 v56.0.0/go.mod h1:D8cdcX98YWJvi7TLo7zM4/h8ZTx6u6fwGEkCdisopo0=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v62 v62.0.0 h1:/6mGCaRywZz9MuHyw9gD1CwsbmBX8GWsbFkwMmHdhl4=
|
||||
github.com/google/go-github/v62 v62.0.0/go.mod h1:EMxeUqGJq2xRu9DYBMwel/mr7kZrzUOfQmmpYrZn2a4=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4=
|
||||
github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
|
||||
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
|
||||
github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
|
@ -21,37 +32,79 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
|
|||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
|
||||
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
|
||||
github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY=
|
||||
github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
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/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
|
||||
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
|
||||
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||
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/thegeeklab/wp-plugin-go v1.0.2 h1:c5yJZ8RWqEufZwa3ErP8RpnyyGjhyw05yH+oeeuJBeA=
|
||||
github.com/thegeeklab/wp-plugin-go v1.0.2/go.mod h1:gAa0rupkUomiHWjM6/+CtyUrLYgk/qXiRkYtPrOG5Ik=
|
||||
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=
|
||||
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
|
||||
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
|
||||
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2 h1:Mv5i8S1WY+BUNjTjX6lOnB3p8S9mvM+XwfY4R98gx0g=
|
||||
github.com/thegeeklab/wp-plugin-go/v3 v3.0.2/go.mod h1:ij1iJcAVgzerBTqXnmq0bu1VA+hhVVwzXKqiqfoGjjg=
|
||||
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
|
||||
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
|
||||
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
|
||||
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
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-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
|
||||
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=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
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 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
42
internal/doc/main.go
Normal file
42
internal/doc/main.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
//go:build generate
|
||||
// +build generate
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/thegeeklab/wp-github-comment/plugin"
|
||||
plugin_docs "github.com/thegeeklab/wp-plugin-go/v3/docs"
|
||||
plugin_template "github.com/thegeeklab/wp-plugin-go/v3/template"
|
||||
)
|
||||
|
||||
func main() {
|
||||
tmpl := "https://raw.githubusercontent.com/thegeeklab/woodpecker-plugins/main/templates/docs-data.yaml.tmpl"
|
||||
client := http.Client{
|
||||
Timeout: 30 * time.Second,
|
||||
}
|
||||
|
||||
p := plugin.New(nil)
|
||||
|
||||
out, err := plugin_template.Render(context.Background(), client, tmpl, plugin_docs.GetTemplateData(p.App))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
outputFile := flag.String("output", "", "Output file path")
|
||||
flag.Parse()
|
||||
|
||||
if *outputFile == "" {
|
||||
panic("no output file specified")
|
||||
}
|
||||
|
||||
err = os.WriteFile(*outputFile, []byte(out), 0o644)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v56/github"
|
||||
)
|
||||
|
||||
type commentClient struct {
|
||||
Message string
|
||||
Update bool
|
||||
Key string
|
||||
Repo string
|
||||
Owner string
|
||||
IssueNum int
|
||||
|
||||
*github.Client
|
||||
}
|
||||
|
||||
func (cc *commentClient) issueComment(ctx context.Context) error {
|
||||
var (
|
||||
err error
|
||||
comment *github.IssueComment
|
||||
resp *github.Response
|
||||
)
|
||||
|
||||
issueComment := &github.IssueComment{
|
||||
Body: &cc.Message,
|
||||
}
|
||||
|
||||
if cc.Update {
|
||||
// Append plugin comment ID to comment message so we can search for it later
|
||||
message := fmt.Sprintf("%s\n<!-- id: %s -->\n", cc.Message, cc.Key)
|
||||
issueComment.Body = &message
|
||||
|
||||
comment, err = cc.comment(ctx)
|
||||
|
||||
if err == nil && comment != nil {
|
||||
_, resp, err = cc.Client.Issues.EditComment(ctx, cc.Owner, cc.Repo, *comment.ID, issueComment)
|
||||
}
|
||||
}
|
||||
|
||||
if err == nil && resp == nil {
|
||||
_, _, err = cc.Client.Issues.CreateComment(ctx, cc.Owner, cc.Repo, cc.IssueNum, issueComment)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cc *commentClient) comment(ctx context.Context) (*github.IssueComment, error) {
|
||||
var allComments []*github.IssueComment
|
||||
|
||||
opts := &github.IssueListCommentsOptions{}
|
||||
|
||||
for {
|
||||
comments, resp, err := cc.Client.Issues.ListComments(ctx, cc.Owner, cc.Repo, cc.IssueNum, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
allComments = append(allComments, comments...)
|
||||
|
||||
if resp.NextPage == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
opts.Page = resp.NextPage
|
||||
}
|
||||
|
||||
for _, comment := range allComments {
|
||||
if strings.Contains(*comment.Body, fmt.Sprintf("<!-- id: %s -->", cc.Key)) {
|
||||
return comment, nil
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:nilnil
|
||||
return nil, nil
|
||||
}
|
|
@ -8,9 +8,9 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/v56/github"
|
||||
"github.com/rs/zerolog/log"
|
||||
"golang.org/x/oauth2"
|
||||
gh "github.com/thegeeklab/wp-github-comment/github"
|
||||
plugin_file "github.com/thegeeklab/wp-plugin-go/v3/file"
|
||||
)
|
||||
|
||||
var ErrPluginEventNotSupported = errors.New("event not supported")
|
||||
|
@ -21,7 +21,6 @@ func (p *Plugin) run(ctx context.Context) error {
|
|||
return fmt.Errorf("validation failed: %w", err)
|
||||
}
|
||||
|
||||
//nolint:contextcheck
|
||||
if err := p.Execute(); err != nil {
|
||||
return fmt.Errorf("execution failed: %w", err)
|
||||
}
|
||||
|
@ -38,7 +37,7 @@ func (p *Plugin) Validate() error {
|
|||
}
|
||||
|
||||
if p.Settings.Message != "" {
|
||||
if p.Settings.Message, p.Settings.IsFile, err = readStringOrFile(p.Settings.Message); err != nil {
|
||||
if p.Settings.Message, p.Settings.IsFile, err = plugin_file.ReadStringOrFile(p.Settings.Message); err != nil {
|
||||
return fmt.Errorf("error while reading %s: %w", p.Settings.Message, err)
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +57,7 @@ func (p *Plugin) Validate() error {
|
|||
p.Settings.Key = fmt.Sprintf("%x", hash)
|
||||
}
|
||||
|
||||
if p.Settings.Key, _, err = readStringOrFile(p.Settings.Key); err != nil {
|
||||
if p.Settings.Key, _, err = plugin_file.ReadStringOrFile(p.Settings.Key); err != nil {
|
||||
return fmt.Errorf("error while reading %s: %w", p.Settings.Key, err)
|
||||
}
|
||||
|
||||
|
@ -67,23 +66,14 @@ 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})
|
||||
tc := oauth2.NewClient(
|
||||
context.WithValue(p.Network.Context, oauth2.HTTPClient, p.Network.Client),
|
||||
ts,
|
||||
)
|
||||
|
||||
client := github.NewClient(tc)
|
||||
client.BaseURL = p.Settings.baseURL
|
||||
|
||||
commentClient := commentClient{
|
||||
Client: client,
|
||||
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,
|
||||
client := gh.NewClient(p.Network.Context, p.Settings.baseURL, p.Settings.APIKey, p.Network.Client)
|
||||
client.Issue.Opt = gh.IssueOptions{
|
||||
Repo: p.Metadata.Repository.Name,
|
||||
Owner: p.Metadata.Repository.Owner,
|
||||
Message: p.Settings.Message,
|
||||
Update: p.Settings.Update,
|
||||
Key: p.Settings.Key,
|
||||
Number: p.Metadata.Curr.PullRequest,
|
||||
}
|
||||
|
||||
if p.Settings.SkipMissing && !p.Settings.IsFile {
|
||||
|
@ -93,7 +83,7 @@ func (p *Plugin) Execute() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
err := commentClient.issueComment(p.Network.Context)
|
||||
_, err := client.Issue.AddComment(p.Network.Context)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create or update comment: %w", err)
|
||||
}
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
wp "github.com/thegeeklab/wp-plugin-go/plugin"
|
||||
plugin_base "github.com/thegeeklab/wp-plugin-go/v3/plugin"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
//go:generate go run ../internal/doc/main.go -output=../docs/data/data-raw.yaml
|
||||
|
||||
// Plugin implements provide the plugin.
|
||||
type Plugin struct {
|
||||
*wp.Plugin
|
||||
*plugin_base.Plugin
|
||||
Settings *Settings
|
||||
}
|
||||
|
||||
|
@ -26,13 +30,85 @@ type Settings struct {
|
|||
baseURL *url.URL
|
||||
}
|
||||
|
||||
func New(options wp.Options, settings *Settings) *Plugin {
|
||||
p := &Plugin{}
|
||||
func New(e plugin_base.ExecuteFunc, build ...string) *Plugin {
|
||||
p := &Plugin{
|
||||
Settings: &Settings{},
|
||||
}
|
||||
|
||||
options.Execute = p.run
|
||||
options := plugin_base.Options{
|
||||
Name: "wp-github-comment",
|
||||
Description: "Add comments to GitHub Issues and Pull Requests",
|
||||
Flags: Flags(p.Settings, plugin_base.FlagsPluginCategory),
|
||||
Execute: p.run,
|
||||
HideWoodpeckerFlags: true,
|
||||
}
|
||||
|
||||
p.Plugin = wp.New(options)
|
||||
p.Settings = settings
|
||||
if len(build) > 0 {
|
||||
options.Version = build[0]
|
||||
}
|
||||
|
||||
if len(build) > 1 {
|
||||
options.VersionMetadata = fmt.Sprintf("date=%s", build[1])
|
||||
}
|
||||
|
||||
if e != nil {
|
||||
options.Execute = e
|
||||
}
|
||||
|
||||
p.Plugin = plugin_base.New(options)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// Flags returns a slice of CLI flags for the plugin.
|
||||
func Flags(settings *Settings, category string) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "api-key",
|
||||
EnvVars: []string{"PLUGIN_API_KEY", "GITHUB_COMMENT_API_KEY"},
|
||||
Usage: "personal access token to access the GitHub API",
|
||||
Destination: &settings.APIKey,
|
||||
Category: category,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "base-url",
|
||||
EnvVars: []string{"PLUGIN_BASE_URL", "GITHUB_COMMENT_BASE_URL"},
|
||||
Usage: "API URL",
|
||||
Value: "https://api.github.com/",
|
||||
Destination: &settings.BaseURL,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "key",
|
||||
EnvVars: []string{"PLUGIN_KEY", "GITHUB_COMMENT_KEY"},
|
||||
Usage: "unique identifier to assign to a comment",
|
||||
Destination: &settings.Key,
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "message",
|
||||
EnvVars: []string{"PLUGIN_MESSAGE", "GITHUB_COMMENT_MESSAGE"},
|
||||
Usage: "path to file or string that contains the comment text",
|
||||
Destination: &settings.Message,
|
||||
Category: category,
|
||||
Required: true,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "update",
|
||||
EnvVars: []string{"PLUGIN_UPDATE", "GITHUB_COMMENT_UPDATE"},
|
||||
Usage: "enable update of an existing comment that matches the key",
|
||||
Value: false,
|
||||
Destination: &settings.Update,
|
||||
Category: category,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "skip-missing",
|
||||
EnvVars: []string{"PLUGIN_SKIP_MISSING", "GITHUB_COMMENT_SKIP_MISSING"},
|
||||
Usage: "skip comment creation if the given message file does not exist",
|
||||
Value: false,
|
||||
Destination: &settings.SkipMissing,
|
||||
Category: category,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func readStringOrFile(input string) (string, bool, error) {
|
||||
//nolint:gomnd
|
||||
if len(input) > 255 {
|
||||
return input, false, nil
|
||||
}
|
||||
|
||||
// Check if input is a file path
|
||||
if _, err := os.Stat(input); err != nil && os.IsNotExist(err) {
|
||||
// No file found => use input as result
|
||||
return input, false, nil
|
||||
} else if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
result, err := os.ReadFile(input)
|
||||
if err != nil {
|
||||
return "", true, err
|
||||
}
|
||||
|
||||
return string(result), true, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user