-
Notifications
You must be signed in to change notification settings - Fork 12
feat: granular PR commits #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
6e7f070
5f5a5b5
313714b
3445ead
b20f82d
d784e28
7c61ab8
643751a
d311d9c
88e26c3
f16e829
5c55bcb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,34 +368,52 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act | |
return "", fmt.Errorf("error getting worktree: %w", err) | ||
} | ||
|
||
logging.Info("Commit and pushing changes to git") | ||
|
||
if err := g.Add("."); err != nil { | ||
return "", fmt.Errorf("error adding changes: %w", err) | ||
isSigned := "" | ||
if environment.GetSignedCommits() { | ||
isSigned = " (signed)" | ||
} | ||
logging.Info("Commit and pushing changes to git " + isSigned) | ||
|
||
var commitMessage string | ||
if action == environment.ActionRunWorkflow { | ||
mfbx9da4 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
commitMessage = fmt.Sprintf("ci: regenerated with OpenAPI Doc %s, Speakeasy CLI %s", openAPIDocVersion, speakeasyVersion) | ||
if sourcesOnly { | ||
commitMessage = fmt.Sprintf("ci: regenerated with Speakeasy CLI %s", speakeasyVersion) | ||
} | ||
} else if action == environment.ActionSuggest { | ||
commitMessage = fmt.Sprintf("ci: suggestions for OpenAPI doc %s", doc) | ||
speakeasyVersionSuffix := "(v" + speakeasyVersion + ")" | ||
|
||
commits := []struct { | ||
paths []string | ||
msg string | ||
}{ | ||
{paths: []string{"**/.speakeasy/", "*gen.yaml", "*gen.lock", "*workflow.yaml", "*workflow.lock"}, msg: "build: Speakeasy config and lock files " + speakeasyVersionSuffix}, | ||
{paths: []string{"*.md"}, msg: "docs: regenerate markdown files " + speakeasyVersionSuffix}, | ||
{paths: []string{"."}, msg: "feat: regenerate SDK " + speakeasyVersionSuffix}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will cause the PR description to be
The target being rebuilt may also not be an SDK. (Terraform and other internal thing I'm working on 😉) Maybe best to keep it similar to the old message and consider dropping the CLI and version part? |
||
} | ||
|
||
// Create commit message | ||
var lastCommitHash plumbing.Hash | ||
if !environment.GetSignedCommits() { | ||
commitHash, err := w.Commit(commitMessage, &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: "speakeasybot", | ||
Email: "[email protected]", | ||
When: time.Now(), | ||
}, | ||
All: true, | ||
}) | ||
var err error | ||
|
||
err = w.Reset(&git.ResetOptions{Mode: git.SoftReset}) | ||
if err != nil { | ||
return "", fmt.Errorf("error committing changes: %w", err) | ||
return "", fmt.Errorf("error resetting: %w", err) | ||
} | ||
|
||
for i, commit := range commits { | ||
for _, path := range commit.paths { | ||
if err = g.Add(path); err != nil { | ||
logging.Info(fmt.Errorf("unable to add changes for %v: %w", path, err).Error()) | ||
} | ||
} | ||
|
||
commitHash, err := w.Commit(commit.msg, &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: "speakeasybot", | ||
Email: "[email protected]", | ||
When: time.Now(), | ||
}, | ||
AllowEmptyCommits: false, | ||
All: i == len(commits)-1, | ||
}) | ||
if err != nil { | ||
logging.Info(fmt.Errorf("unable to commit changes for %v: %w", commit.paths, err).Error()) | ||
} | ||
lastCommitHash = commitHash | ||
} | ||
|
||
if err := g.repo.Push(&git.PushOptions{ | ||
|
@@ -404,7 +422,11 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act | |
}); err != nil { | ||
return "", pushErr(err) | ||
} | ||
return commitHash.String(), nil | ||
return lastCommitHash.String(), nil | ||
} | ||
|
||
if err := g.Add("."); err != nil { | ||
return "", fmt.Errorf("error adding changes: %w", err) | ||
} | ||
|
||
branch, err := g.GetCurrentBranch() | ||
|
@@ -447,7 +469,7 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act | |
|
||
// Commit changes | ||
commitResult, _, err := g.client.Git.CreateCommit(context.Background(), owner, repo, &github.Commit{ | ||
Message: github.String(commitMessage), | ||
Message: github.String(commits[len(commits)-1].msg), | ||
Tree: &github.Tree{SHA: tree.SHA}, | ||
Parents: []*github.Commit{parentCommit}}, &github.CreateCommitOptions{}) | ||
if err != nil { | ||
|
@@ -520,6 +542,7 @@ func (g *Git) createAndPushTree(ref *github.Reference, sourceFiles git.Status) ( | |
tree, _, err = g.client.Git.CreateTree(context.Background(), owner, repo, *ref.Object.SHA, entries) | ||
return tree, err | ||
} | ||
|
||
func (g *Git) Add(arg string) error { | ||
// We execute this manually because go-git doesn't properly support gitignore | ||
cmd := exec.Command("git", "add", arg) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
INPUT_MODE="pr" | ||
INPUT_ACTION="generate" | ||
INPUT_LANGUAGES="- go" | ||
GITHUB_REPOSITORY="speakeasy-api/sdk-generation-action-test-repo" | ||
INPUT_FORCE=true | ||
RUN_FINALIZE=true | ||
INPUT_SIGNED_COMMITS=true | ||
INPUT_SIGNED_COMMITS=false |
Uh oh!
There was an error while loading. Please reload this page.