示例#1
0
文件: main.go 项目: xoebus/checkin
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)
	}
}
示例#2
0
文件: db_test.go 项目: xoebus/checkin
	"github.com/contraband/checkin"
	"github.com/contraband/checkin/db"
)

var _ = Describe("DB", func() {
	var dbConn *sql.DB
	var sqlDB db.DB

	BeforeEach(func() {
		postgresRunner.Truncate()

		dbConn = postgresRunner.Open()
		Eventually(dbConn.Ping, 5*time.Second).ShouldNot(HaveOccurred())

		sqlDB = db.NewSQL(lagertest.NewTestLogger("db"), dbConn)
	})

	AfterEach(func() {
		err := dbConn.Close()
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("enqueing pull requests to be checked", func() {
		It("enqueues them", func() {
			pr := checkin.PullRequest{
				Owner:      "contraband",
				Repository: "checkin",
				SHA:        "a59675a7206f7ee4334176c4f8096e4511704d73",
			}
			err := sqlDB.EnqueuePullRequest(pr)