main.go 2.12 KB
Newer Older
Mustafa Gezen's avatar
Mustafa Gezen committed
1
2
3
package main

import (
4
5
6
7
	"cloud.google.com/go/storage"
	"context"
	"log"
	"strings"
Mustafa Gezen's avatar
Mustafa Gezen committed
8

9
10
	"github.com/mstg/srpmproc/internal"
	"github.com/spf13/cobra"
Mustafa Gezen's avatar
Mustafa Gezen committed
11
12
13
)

var (
14
15
16
17
18
19
	sourceRpm         string
	sshKeyLocation    string
	sshUser           string
	upstreamPrefix    string
	branch            string
	gcsBucket         string
20
21
	gitCommitterName  string
	gitCommitterEmail string
Mustafa Gezen's avatar
Mustafa Gezen committed
22
23
24
)

var root = &cobra.Command{
25
26
	Use: "srpmproc",
	Run: mn,
Mustafa Gezen's avatar
Mustafa Gezen committed
27
28
29
}

func mn(_ *cobra.Command, _ []string) {
30
31
32
33
34
35
36
37
38
39
40
41
42
43
	ctx := context.Background()
	client, err := storage.NewClient(ctx)
	if err != nil {
		log.Fatalf("could not create gcloud client: %v", err)
	}

	sourceRpmLocation := ""
	if strings.HasPrefix(sourceRpm, "file://") {
		sourceRpmLocation = strings.TrimPrefix(sourceRpm, "file://")
	} else {
		log.Fatal("non-local SRPMs are currently not supported")
	}

	internal.ProcessRPM(&internal.ProcessData{
44
45
46
47
48
49
50
51
		RpmLocation:       sourceRpmLocation,
		UpstreamPrefix:    upstreamPrefix,
		SshKeyLocation:    sshKeyLocation,
		SshUser:           sshUser,
		Branch:            branch,
		Bucket:            client.Bucket(gcsBucket),
		GitCommitterName:  gitCommitterName,
		GitCommitterEmail: gitCommitterEmail,
52
	})
Mustafa Gezen's avatar
Mustafa Gezen committed
53
54
55
}

func main() {
56
57
58
59
60
61
62
63
	root.Flags().StringVar(&sourceRpm, "source-rpm", "", "Location of RPM to process")
	_ = root.MarkFlagRequired("source-rpm")
	root.Flags().StringVar(&upstreamPrefix, "upstream-prefix", "", "Upstream git repository prefix")
	_ = root.MarkFlagRequired("upstream-prefix")
	root.Flags().StringVar(&branch, "branch", "", "Upstream branch")
	_ = root.MarkFlagRequired("branch")
	root.Flags().StringVar(&gcsBucket, "gcs-bucket", "", "Bucket to use as blob storage")
	_ = root.MarkFlagRequired("gcs-bucket")
64
65
	root.Flags().StringVar(&gitCommitterName, "git-committer-name", "distrobuild-bot", "Name of committer")
	root.Flags().StringVar(&gitCommitterEmail, "git-committer-email", "mustafa+distrobuild@bycrates.com", "Email of committer")
66

67
68
	root.Flags().StringVar(&sshKeyLocation, "ssh-key-location", "", "Location of the SSH key to use to authenticate against upstream")
	root.Flags().StringVar(&sshUser, "ssh-user", "git", "SSH User")
69
70
71
72

	if err := root.Execute(); err != nil {
		log.Fatal(err)
	}
Mustafa Gezen's avatar
Mustafa Gezen committed
73
}