mirror of
https://github.com/lddsb/drone-goreportcard
synced 2024-11-22 10:51:56 +01:00
start on the road
This commit is contained in:
commit
a267fc8744
36
.drone.yml
Normal file
36
.drone.yml
Normal file
@ -0,0 +1,36 @@
|
||||
---
|
||||
kind: pipeline
|
||||
name: build
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
pull: always
|
||||
image: golang
|
||||
commands:
|
||||
- go build -a -o drone-goreportcard .
|
||||
environment:
|
||||
- GO111MODULE=on
|
||||
- CGO_ENABLED=0
|
||||
|
||||
- name: dryrun
|
||||
pull: always
|
||||
image: plugins/docker
|
||||
settings:
|
||||
cache_from: lddsb/drone-goreportcard
|
||||
dockerfile: Dockerfile
|
||||
dryrun: true
|
||||
repo: lddsb/drone-goreportcard
|
||||
tags: latest
|
||||
|
||||
- name: publish
|
||||
pull: always
|
||||
image: plugins/docker
|
||||
settings:
|
||||
cache_from: lddsb/drone-goreportcard
|
||||
dockerfile: Dockerfile
|
||||
repo: lddsb/drone-goreportcard
|
||||
tags: latest
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
drone-goreportcard
|
10
Dockerfile
Normal file
10
Dockerfile
Normal file
@ -0,0 +1,10 @@
|
||||
FROM alpine:latest
|
||||
|
||||
RUN apk update && \
|
||||
apk add \
|
||||
ca-certificates && \
|
||||
rm -rf /var/cache/apk/*
|
||||
|
||||
COPY drone-goreportcard /bin
|
||||
|
||||
ENTRYPOINT ["/bin/drone-goreportcard"]
|
16
README.md
Normal file
16
README.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Go Report Card Drone Plugin
|
||||
[![Build Status](https://drone.lddsb.com/api/badges/lddsb/drone-goreportcard/status.svg)](https://drone.lddsb.com/lddsb/drone-goreportcard)
|
||||
[Drone CI](https://drone.io) plugin to auto refresh your project status in [go report card](https://goreportcard.com)
|
||||
### Usage
|
||||
|
||||
```yaml
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
...
|
||||
- name: goreportcard
|
||||
pull: always
|
||||
image: lddsb/drone-goreportcard
|
||||
|
||||
```
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module drone-goreportcard
|
||||
|
||||
go 1.12
|
||||
|
||||
require github.com/urfave/cli v1.20.0
|
2
go.sum
Normal file
2
go.sum
Normal file
@ -0,0 +1,2 @@
|
||||
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=
|
||||
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
|
44
main.go
Normal file
44
main.go
Normal file
@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// Version `cli version`
|
||||
var Version = "20190309"
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Name = "Drone Plugin GoReportCard"
|
||||
app.Usage = "fresh go report card message"
|
||||
app.Copyright = "© 2019 Dee Luo"
|
||||
app.Authors = []cli.Author{
|
||||
{
|
||||
Name: "Dee Luo",
|
||||
Email: "luodi0128@gmail.com",
|
||||
},
|
||||
}
|
||||
app.Action = run
|
||||
app.Version = Version
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "config.url",
|
||||
Usage: "repository http url",
|
||||
EnvVar: "DRONE_GIT_HTTP_URL",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); nil != err {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func run(c *cli.Context) error {
|
||||
p := Plugin{
|
||||
URL: c.String("config.url"),
|
||||
}
|
||||
return p.Exec()
|
||||
}
|
48
plugin.go
Normal file
48
plugin.go
Normal file
@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type (
|
||||
// Plugin `plugin struct`
|
||||
Plugin struct {
|
||||
URL string
|
||||
}
|
||||
)
|
||||
|
||||
var baseURL = "https://goreportcard.com/"
|
||||
|
||||
// Exec `exec plugin`
|
||||
func (p *Plugin) Exec() error {
|
||||
urlLen := len(p.URL)
|
||||
if 4 > urlLen {
|
||||
return errors.New("invalid repository url")
|
||||
}
|
||||
|
||||
suffix := p.URL[urlLen-4:]
|
||||
if ".git" == suffix {
|
||||
p.URL = p.URL[:urlLen-4]
|
||||
}
|
||||
resp, err := http.Get(baseURL + "checks?repo=" + p.URL)
|
||||
if nil != err {
|
||||
return err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
if http.StatusOK != resp.StatusCode {
|
||||
bs, err := ioutil.ReadAll(resp.Body)
|
||||
if nil == err {
|
||||
return errors.New("API response error: " + string(bs))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
log.Println("Everything is OK")
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user