Exemplo n.º 1
0
func main() {
	logger := lager.NewLogger("checkin")
	logger.RegisterSink(lager.NewWriterSink(os.Stdout, lager.INFO))

	var opts Opts

	_, err := flags.Parse(&opts)
	if err != nil {
		logger.Error("parsing-flags", err)
		os.Exit(1)
	}

	// ts := oauth2.StaticTokenSource(
	// 	&oauth2.Token{AccessToken: opts.GitHubAccessToken},
	// )
	// tc := oauth2.NewClient(oauth2.NoContext, ts)
	// githubClient := github.NewClient(tc)

	// checker := build.NewConcourseChecker()
	// checker = build.NewStatusReporter(checker, githubClient.Repositories)

	dbConn, err := migration.Open(opts.DBDriver, opts.DBURL, migrations.Migrations)
	if err != nil {
		logger.Error("failed-to-run-migrations", err)
		os.Exit(1)
	}
	sqlDB := db.NewSQL(logger.Session("db"), dbConn)

	enqueuer := build.NewEnqueuer(sqlDB)
	apiServer := api.NewServer(opts.GitHubSecret, enqueuer)

	members := []grouper.Member{
		{
			"api",
			http_server.New(
				opts.Addr,
				apiServer,
			),
		},
	}

	group := grouper.NewParallel(os.Interrupt, members)
	running := ifrit.Invoke(sigmon.New(group))

	logger.Info("listening", lager.Data{
		"api": opts.Addr,
	})

	err = <-running.Wait()
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}
Exemplo n.º 2
0
	"github.com/contraband/checkin"
	"github.com/contraband/checkin/build"
	"github.com/contraband/checkin/build/fakes"
)

var _ = Describe("Enqueuer", func() {
	var (
		queueDB  *fakes.FakeQueueDB
		enqueuer *build.Enqueuer

		event *github.PullRequestEvent
	)

	BeforeEach(func() {
		queueDB = new(fakes.FakeQueueDB)
		enqueuer = build.NewEnqueuer(queueDB)

		event = &github.PullRequestEvent{
			Action: github.String("opened"),
			PullRequest: &github.PullRequest{
				Head: &github.PullRequestBranch{
					User: &github.User{
						Login: github.String("contraband"),
					},
					Repo: &github.Repository{
						Name: github.String("checkin"),
					},
					SHA: github.String("abc123"),
				},
			},
		}