-
Notifications
You must be signed in to change notification settings - Fork 78
/
create_salsa_project.go
47 lines (39 loc) · 1.14 KB
/
create_salsa_project.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
"net/url"
"os"
)
func execCreateSalsaProject(args []string) {
fs := flag.NewFlagSet("create-salsa-project", flag.ExitOnError)
fs.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s create-salsa-project <project-name>\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Example: %s create-salsa-project golang-github-mattn-go-sqlite3\n", os.Args[0])
}
if err := fs.Parse(args); err != nil {
log.Fatalf("parse: %s", err)
}
if fs.NArg() != 1 {
fs.Usage()
os.Exit(1)
}
projectName := fs.Arg(0)
// The source code of the corresponding server can be found at:
// https://salsa.debian.org/go-team/infra/pkg-go-tools/-/tree/master/cmd/pgt-api-server
u, _ := url.Parse("https://pgt-api-server.debian.net/v1/createrepo")
q := u.Query()
q.Set("repo", projectName)
u.RawQuery = q.Encode()
resp, err := http.Post(u.String(), "", nil)
if err != nil {
log.Fatalf("http post: %s", err)
}
if got, want := resp.StatusCode, http.StatusOK; got != want {
b, _ := ioutil.ReadAll(resp.Body)
log.Fatalf("unexpected HTTP status code: got %d, want %d (response: %s)", got, want, string(b))
}
}