-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Migrate gh-pr-comment to Go * Migrate gh-pr-upload to Go * Add install script * Update README
- Loading branch information
Showing
22 changed files
with
713 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
*.egg-info | ||
*.pyc | ||
build | ||
gh-pr-comment | ||
gh-pr-upload | ||
!cmd/gh-pr-comment | ||
!cmd/gh-pr-upload | ||
gh-pr-comment.upx | ||
gh-pr-upload.upx | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
builds: | ||
- id: gh-pr-comment | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
main: ./cmd/gh-pr-comment/main.go | ||
binary: gh-pr-comment | ||
ldflags: | ||
- "-s -w" | ||
hooks: | ||
post: | ||
- upx "{{ .Path }}" | ||
- id: gh-pr-upload | ||
env: | ||
- CGO_ENABLED=0 | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
goarch: | ||
- amd64 | ||
- arm64 | ||
main: ./cmd/gh-pr-upload/main.go | ||
binary: gh-pr-upload | ||
ldflags: | ||
- "-s -w" | ||
hooks: | ||
post: | ||
- upx "{{ .Path }}" | ||
archives: | ||
- builds: | ||
- gh-pr-comment | ||
- gh-pr-upload | ||
format: tar.gz | ||
format_overrides: | ||
- goos: windows | ||
format: zip | ||
checksum: | ||
name_template: 'checksums.txt' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,40 @@ | ||
dist: xenial | ||
language: python | ||
python: | ||
- 2.7 | ||
- 3.6 | ||
dist: focal | ||
language: go | ||
go: 1.14 | ||
branches: | ||
only: | ||
- master | ||
- "/^[0-9]+\\.[0-9]+\\.[0-9]+/" | ||
- "/^deploy-test/" | ||
|
||
addons: | ||
apt: | ||
packages: | ||
- upx-ucl | ||
|
||
env: | ||
global: | ||
- CGO_ENABLED=0 | ||
|
||
install: | ||
- pip install pycodestyle pyflakes | ||
- python setup.py install | ||
- ./tests/coding-style.sh | ||
- go build -ldflags="-s -w" ./cmd/gh-pr-comment | ||
- go build -ldflags="-s -w" ./cmd/gh-pr-upload | ||
- upx ./gh-pr-comment | ||
- upx ./gh-pr-upload | ||
- sudo cp ./gh-pr-comment /usr/local/bin/ | ||
- sudo cp ./gh-pr-upload /usr/local/bin/ | ||
|
||
script: | ||
- ./tests/exec-test.sh | ||
- go vet ./... | ||
- go test ./... | ||
- .ci/upload-test.sh | ||
- curl -sfL https://git.io/goreleaser | sh -s -- check # check goreleaser config | ||
|
||
before_deploy: | ||
- export GITHUB_TOKEN=${GITHUB_TOKEN_DEPLOY} | ||
|
||
deploy: | ||
provider: pypi | ||
user: at-wat | ||
password: | ||
secure: Abg3hVOGYXSXDEqyQarJjgLbtoIrNLsaald56fA9h0c88h/cmvUKwVHkEGkyZnfJZlT4CHiNHH3vsqC8cHTmkQLlp6kehrGzpUEagaoWCUkE7TR+z8c2HUwYNFU2mDs7TxlvRjOikluFsywjE6GBh0l4ueXMEiM4KBu/KwEpW5O9axvFjzF49o2znT/zPjhEmNHeLEF+pronm/QuR/91q/TIErHFV5ilV4a/zhp66VBUAyQ31yxC1bEV7iSsLHsiwJJIlJTovlgEHVq+j3pD7MoElmdkAAw74BMUXjO3+Ua44qbxfmfQayT6dpeyEPqipHF3Ej262eGuLyaie57oW/tZ6S3MDBEewIp5JC3i79+bZcJ06Btyf+iT75Gac4CSAiT2GCQ7G9O3dQwUFWpNeDDB1+GEZ/R+FWH4Uvwo+BPJi4DNf+UG5IObkGN6YPDxZabzbQxlbHO7vrwNCIiFKebep1bjv7VnMlXu2fqi7TZq9fgtw1N0ignuRcd0ZLr73YcWIF1EP1MfXvxirI1SL5P8GplbnRExCecVCpGGbFmViwgi4r4nlcKzr5bXMnzXDQrSBgTHhIhJJ5qvnvGLZxWfVtNbe5pH0js1ht08vSsKVa0XzlpjdKiWIFdc3vy626xVxKy3wMSS0XOqyuPuJCkqsiAb3wPqwvoOOFH+tso= | ||
on: | ||
tags: true | ||
python: 3.6 | ||
- provider: script | ||
script: curl -sL https://git.io/goreleaser | bash | ||
on: | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/google/go-github/v32/github" | ||
"golang.org/x/oauth2" | ||
|
||
"github.com/at-wat/gh-pr-comment/pkg/cienv" | ||
_ "github.com/at-wat/gh-pr-comment/pkg/cienv/travis" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 3 { | ||
fmt.Fprintf(os.Stderr, "usage: %s title comment\n", os.Args[0]) | ||
fmt.Fprint(os.Stderr, `env: | ||
GITHUB_TOKEN (or TRAVIS_BOT_GITHUB_TOKEN): | ||
token with comment write permission | ||
env for Travis-CI: | ||
TRAVIS: | ||
must be true | ||
TRAVIS_PULL_REQUEST_SLUG: | ||
owner/repos (TRAVIS_REPO_SLUG is used if not set) | ||
TRAVIS_PULL_REQUEST: | ||
pull request number | ||
`) | ||
os.Exit(1) | ||
} | ||
title := os.Args[1] | ||
body := os.Args[2] | ||
|
||
env, err := cienv.Detect() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
if !env.IsPullRequest { | ||
fmt.Fprint(os.Stderr, "info: not on a pull request\n") | ||
os.Exit(0) | ||
} | ||
|
||
var ghToken string | ||
|
||
if t, ok := os.LookupEnv("TRAVIS_BOT_GITHUB_TOKEN"); ok { | ||
ghToken = t | ||
} else if t, ok := os.LookupEnv("GITHUB_TOKEN"); ok { | ||
ghToken = t | ||
} | ||
|
||
if ghToken == "" { | ||
fmt.Fprint(os.Stderr, "error: neither TRAVIS_BOT_GITHUB_TOKEN nor GITHUB_TOKEN is not set.\n") | ||
os.Exit(1) | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
|
||
tc := oauth2.NewClient( | ||
ctx, | ||
oauth2.StaticTokenSource(&oauth2.Token{AccessToken: ghToken}), | ||
) | ||
|
||
var gh *github.Client | ||
if ep, customEP := os.LookupEnv("GITHUB_API_URL_BASE"); customEP { | ||
var err error | ||
gh, err = github.NewEnterpriseClient(ep, ep, tc) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: failed to init GitHub client: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} else { | ||
gh = github.NewClient(tc) | ||
} | ||
|
||
bodyStr := fmt.Sprintf("## %s\n\n%s", title, body) | ||
_, resp, err := gh.Issues.CreateComment( | ||
ctx, | ||
env.PullRequestSlug.Owner, env.PullRequestSlug.Repo, | ||
env.PullRequest, | ||
&github.IssueComment{Body: &bodyStr}, | ||
) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: failed to call CreateComment API: %v\n", err) | ||
os.Exit(1) | ||
} | ||
if resp.StatusCode < 200 || 300 <= resp.StatusCode { | ||
fmt.Fprintf(os.Stderr, "error: failed to CreateComment: %s\n", resp.Status) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/at-wat/gh-pr-comment/cmd/gh-pr-upload/uploader" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
fmt.Fprintf(os.Stderr, "usage: %s filename\n", os.Args[0]) | ||
fmt.Fprint(os.Stderr, `env: | ||
IMAGE_UPLOADER: imgur(default), s3 | ||
ALLOW_PUBLIC_UPLOADER: set it to enable public uploader | ||
env for imgur: | ||
IMGUR_CLIENT_ID: custom-client-id | ||
env for s3: | ||
AWS_DEFAULT_REGION | ||
AWS_ACCESS_KEY_ID | ||
AWS_SECRET_ACCESS_KEY | ||
AWS_S3_BUCKET | ||
return: image url | ||
`) | ||
os.Exit(1) | ||
} | ||
filename := os.Args[1] | ||
|
||
var ut = uploader.DefaultUploader | ||
if t, ok := os.LookupEnv("IMAGE_UPLOADER"); ok { | ||
var err error | ||
ut, err = uploader.NewUploaderType(t) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "error: failed to parse IMAGE_UPLOADER: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
if ut.Public() { | ||
if _, ok := os.LookupEnv("ALLOW_PUBLIC_UPLOADER"); !ok { | ||
fmt.Fprintf(os.Stderr, "error: public uploader is not allowed, set ALLOW_PUBLIC_UPLOADER to enable\n") | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
u := ut.Uploader() | ||
if err := u.Upload(filename); err != nil { | ||
fmt.Fprintf(os.Stderr, "error: failed to upload: %v\n", err) | ||
os.Exit(1) | ||
} | ||
} |
Oops, something went wrong.