Exemple #1
0
func runGH(
	input io.Reader,
	createIssue func(owner string, repo string, issue *github.IssueRequest) (*github.Issue, *github.Response, error),
) error {
	sha, ok := os.LookupEnv(teamcityVCSNumberEnv)
	if !ok {
		return errors.Errorf("VCS number environment variable %s is not set", teamcityVCSNumberEnv)
	}

	suites, err := lib.ParseGotest(input, "")
	if err != nil {
		return errors.Wrap(err, "failed to parse `go test` output")
	}
	for _, suite := range suites {
		for _, test := range suite.Tests {
			switch test.Status {
			case lib.Failed:
				title := fmt.Sprintf("%s: %s failed under stress", suite.Name, test.Name)
				body := fmt.Sprintf(`SHA: https://github.com/cockroachdb/cockroach/commits/%s

Stress build found a failed test:

%s`, sha, "```\n"+test.Message+"\n```")

				issueRequest := &github.IssueRequest{
					Title: &title,
					Body:  &body,
					Labels: &[]string{
						"Robot",
						"test-failure",
					},
				}
				if _, _, err := createIssue("cockroachdb", "cockroach", issueRequest); err != nil {
					return errors.Wrapf(err, "failed to create GitHub issue %s", github.Stringify(issueRequest))
				}

			}
		}
	}

	return nil
}
Exemple #2
0
func runGH(
	input io.Reader,
	createIssue func(owner string, repo string, issue *github.IssueRequest) (*github.Issue, *github.Response, error),
) error {
	sha, ok := os.LookupEnv(teamcityVCSNumberEnv)
	if !ok {
		return errors.Errorf("VCS number environment variable %s is not set", teamcityVCSNumberEnv)
	}

	buildID, ok := os.LookupEnv(teamcityBuildIDEnv)
	if !ok {
		log.Fatalf("teamcity build ID environment variable %s is not set", teamcityBuildIDEnv)
	}

	serverURL, ok := os.LookupEnv(teamcityServerURLEnv)
	if !ok {
		log.Fatalf("teamcity server URL environment variable %s is not set", teamcityServerURLEnv)
	}

	options := url.Values{}
	options.Add("buildId", buildID)
	options.Add("tab", "buildLog")

	u, err := url.Parse(serverURL)
	if err != nil {
		log.Fatal(err)
	}
	u.Scheme = "https"
	u.Path = "viewLog.html"
	u.RawQuery = options.Encode()

	var inputBuf bytes.Buffer
	input = io.TeeReader(input, &inputBuf)

	var parameters []string
	for _, parameter := range []string{
		propEvalKVEnv,
		tagsEnv,
		goFlagsEnv,
	} {
		if val, ok := os.LookupEnv(parameter); ok {
			parameters = append(parameters, parameter+"="+val)
		}
	}
	newIssueRequest := func(packageName, testName, message string) *github.IssueRequest {
		title := fmt.Sprintf("%s: %s failed under stress", packageName, testName)
		body := fmt.Sprintf(`SHA: https://github.com/cockroachdb/cockroach/commits/%s

Parameters:
%s

Stress build found a failed test: %s

%s`, sha, "```\n"+strings.Join(parameters, "\n")+"\n```", u.String(), "```\n%s\n```")
		// We insert a raw "%s" above so we can figure out the length of the
		// body so far, without the actual error text. We need this length so we
		// can calculate the maximum amount of error text we can include in the
		// issue without exceeding GitHub's limit. We replace that %s in the
		// following Sprintf.
		body = fmt.Sprintf(body, trimIssueRequestBody(message, len(body)))

		return &github.IssueRequest{
			Title: &title,
			Body:  &body,
			Labels: &[]string{
				"Robot",
				"test-failure",
			},
		}
	}

	suites, err := lib.ParseGotest(input, "")
	if err != nil {
		return errors.Wrap(err, "failed to parse `go test` output")
	}
	posted := false
	for _, suite := range suites {
		packageName := suite.Name
		if packageName == "" {
			var ok bool
			packageName, ok = os.LookupEnv(pkgEnv)
			if !ok {
				log.Fatalf("package name environment variable %s is not set", pkgEnv)
			}
		}
		for _, test := range suite.Tests {
			switch test.Status {
			case lib.Failed:
				issueRequest := newIssueRequest(packageName, test.Name, test.Message)
				if _, _, err := createIssue("cockroachdb", "cockroach", issueRequest); err != nil {
					return errors.Wrapf(err, "failed to create GitHub issue %s", github.Stringify(issueRequest))
				}
				posted = true
			}
		}
	}

	const unknown = "(unknown)"

	if !posted {
		packageName, ok := os.LookupEnv(pkgEnv)
		if !ok {
			packageName = unknown
		}
		issueRequest := newIssueRequest(packageName, unknown, inputBuf.String())
		if _, _, err := createIssue("cockroachdb", "cockroach", issueRequest); err != nil {
			return errors.Wrapf(err, "failed to create GitHub issue %s", github.Stringify(issueRequest))
		}
	}

	return nil
}
Exemple #3
0
func runGH(
	input io.Reader,
	createIssue func(owner string, repo string, issue *github.IssueRequest) (*github.Issue, *github.Response, error),
) error {
	sha, ok := os.LookupEnv(teamcityVCSNumberEnv)
	if !ok {
		return errors.Errorf("VCS number environment variable %s is not set", teamcityVCSNumberEnv)
	}

	host, ok := os.LookupEnv(teamcityServerURLEnv)
	if !ok {
		log.Fatalf("teamcity server URL environment variable %s is not set", teamcityServerURLEnv)
	}

	buildID, ok := os.LookupEnv(teamcityBuildIDEnv)
	if !ok {
		log.Fatalf("teamcity build ID environment variable %s is not set", teamcityBuildIDEnv)
	}

	var inputBuf bytes.Buffer
	input = io.TeeReader(input, &inputBuf)

	options := url.Values{}
	options.Add("buildId", buildID)

	u := (&url.URL{
		Scheme:   "https",
		Host:     host,
		Path:     "viewLog.html",
		RawQuery: options.Encode(),
	}).String()

	newIssueRequest := func(packageName, testName, message string) *github.IssueRequest {
		title := fmt.Sprintf("%s: %s failed under stress", packageName, testName)
		body := fmt.Sprintf(`SHA: https://github.com/cockroachdb/cockroach/commits/%s

Stress build found a failed test: %s

%s`, sha, u, "```\n"+trimIssueRequestBody(message)+"\n```")

		return &github.IssueRequest{
			Title: &title,
			Body:  &body,
			Labels: &[]string{
				"Robot",
				"test-failure",
			},
		}
	}

	suites, err := lib.ParseGotest(input, "")
	if err != nil {
		return errors.Wrap(err, "failed to parse `go test` output")
	}
	posted := false
	for _, suite := range suites {
		packageName := suite.Name
		if packageName == "" {
			var ok bool
			packageName, ok = os.LookupEnv(pkgEnv)
			if !ok {
				log.Fatalf("package name environment variable %s is not set", pkgEnv)
			}
		}
		for _, test := range suite.Tests {
			switch test.Status {
			case lib.Failed:
				issueRequest := newIssueRequest(packageName, test.Name, test.Message)
				if _, _, err := createIssue("cockroachdb", "cockroach", issueRequest); err != nil {
					return errors.Wrapf(err, "failed to create GitHub issue %s", github.Stringify(issueRequest))
				}
				posted = true
			}
		}
	}

	if !posted {
		issueRequest := newIssueRequest("(unknown)", "(unknown)", inputBuf.String())
		if _, _, err := createIssue("cockroachdb", "cockroach", issueRequest); err != nil {
			return errors.Wrapf(err, "failed to create GitHub issue %s", github.Stringify(issueRequest))
		}
	}

	return nil
}