<commit_before>package cd

import (
	"context"
	"fmt"
	"regexp"

	"go.skia.org/infra/go/auth"
	"go.skia.org/infra/go/exec"
	"go.skia.org/infra/go/gerrit/rubberstamper"
	"go.skia.org/infra/go/git"
	"go.skia.org/infra/go/gitiles"
	"go.skia.org/infra/go/httputils"
	"go.skia.org/infra/go/louhi"
	"go.skia.org/infra/go/louhi/pubsub"
	"go.skia.org/infra/go/skerr"
	"go.skia.org/infra/task_driver/go/td"
	"golang.org/x/oauth2/google"
)

var uploadedCLRegex = regexp.MustCompile(`https://.*review\.googlesource\.com.*\d+`)

// MaybeUploadCL uploads a CL if there are any diffs in checkoutDir. It builds
// the commit message starting with the given commitSubject. If srcRepo and
// srcCommit are provided, a link back to the source commit is added to the
// commit message.  If louhiPubsubProject and louhiExecutionID are provided,
// a pub/sub message is sent after the CL is uploaded.
func MaybeUploadCL(ctx context.Context, checkoutDir, commitSubject, srcRepo, srcCommit, louhiPubsubProject, louhiExecutionID string) error {
	ctx = td.StartStep(ctx, td.Props("MaybeUploadCL"))
	defer td.EndStep(ctx)

	gitExec, err := git.Executable(ctx)
	if err != nil {
		return skerr.Wrap(err)
	}

	// Did we change anything?
	if _, err := exec.RunCwd(ctx, checkoutDir, gitExec, "diff", "--exit-code"); err != nil {
		// If so, create a CL.

		// Build the commit message.
		commitMsg := commitSubject
		if srcCommit != "" {
			shortCommit := srcCommit
			if len(shortCommit) > 12 {
				shortCommit = shortCommit[:12]
			}
			commitMsg += " for " + shortCommit
		}<commit_msg>[CD] Fix "git diff" command for uploading CLs<commit_after>package cd

import (
	"context"
	"fmt"
	"regexp"

	"go.skia.org/infra/go/auth"
	"go.skia.org/infra/go/exec"
	"go.skia.org/infra/go/gerrit/rubberstamper"
	"go.skia.org/infra/go/git"
	"go.skia.org/infra/go/gitiles"
	"go.skia.org/infra/go/httputils"
	"go.skia.org/infra/go/louhi"
	"go.skia.org/infra/go/louhi/pubsub"
	"go.skia.org/infra/go/skerr"
	"go.skia.org/infra/task_driver/go/td"
	"golang.org/x/oauth2/google"
)

var uploadedCLRegex = regexp.MustCompile(`https://.*review\.googlesource\.com.*\d+`)

// MaybeUploadCL uploads a CL if there are any diffs in checkoutDir. It builds
// the commit message starting with the given commitSubject. If srcRepo and
// srcCommit are provided, a link back to the source commit is added to the
// commit message.  If louhiPubsubProject and louhiExecutionID are provided,
// a pub/sub message is sent after the CL is uploaded.
func MaybeUploadCL(ctx context.Context, checkoutDir, commitSubject, srcRepo, srcCommit, louhiPubsubProject, louhiExecutionID string) error {
	ctx = td.StartStep(ctx, td.Props("MaybeUploadCL"))
	defer td.EndStep(ctx)

	gitExec, err := git.Executable(ctx)
	if err != nil {
		return skerr.Wrap(err)
	}

	// Did we change anything?
	if _, err := exec.RunCwd(ctx, checkoutDir, gitExec, "diff", "HEAD", "--exit-code"); err != nil {
		// If so, create a CL.

		// Build the commit message.
		commitMsg := commitSubject
		if srcCommit != "" {
			shortCommit := srcCommit
			if len(shortCommit) > 12 {
				shortCommit = shortCommit[:12]
			}
			commitMsg += " for " + shortCommit
		}
{'fraction_non_alphanumeric': 0.1397338403041825, 'fraction_numerical': 0.0031685678073510772, 'mean_word_length': 3.7616892911010558, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7006937', 'n_tokens_mistral': 1241, 'n_tokens_neox': 1167, 'n_words': 280}