Skip to content

Commit

Permalink
emit annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
xtuc committed May 8, 2020
1 parent 4426174 commit 7ea2965
Showing 1 changed file with 12 additions and 31 deletions.
43 changes: 12 additions & 31 deletions cmd/checker/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -51,33 +48,9 @@ func main() {
return
}

if subcommand == "review" {
review(flag.Arg(1), flag.Arg(2))
return
}

panic("unknown subcommand")
}

func review(pr, run_id string) {
url := "https://github-ci.cdnjs.com/review"
var jsonStr = []byte(fmt.Sprintf(`{"pr":"%s", "run_id": "%s"}`, pr, run_id))
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
util.Check(err)
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
util.Check(err)

defer resp.Body.Close()

fmt.Println("response Status:", resp.Status)
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println("response Body:", string(body))

}

func showFiles(path string) {
ctx := util.ContextWithName(path)
pckg, readerr := packages.ReadPackageJSON(ctx, path)
Expand Down Expand Up @@ -216,18 +189,26 @@ func lintPackage(path string) {
}

func err(ctx context.Context, s string) {
util.Printf(ctx, "error: "+s)
if prefix, ok := ctx.Value("loggerPrefix").(string); ok {
fmt.Printf("::error file=%s,line=1,col=1::%s\n", prefix, s)
} else {
fmt.Printf("error: %s\n", s)
}
errCount += 1
}

func warn(ctx context.Context, s string) {
util.Printf(ctx, "warning: "+s)
if prefix, ok := ctx.Value("loggerPrefix").(string); ok {
fmt.Printf("::warning file=%s,line=1,col=1::%s\n", prefix, s)
} else {
fmt.Printf("warning: %s\n", s)
}
}

func shouldBeEmpty(name string) string {
return fmt.Sprintf("%s should be empty\n", name)
return fmt.Sprintf("%s should be empty", name)
}

func shouldNotBeEmpty(name string) string {
return fmt.Sprintf("%s should be specified\n", name)
return fmt.Sprintf("%s should be specified", name)
}

0 comments on commit 7ea2965

Please sign in to comment.