-
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
Open
mfbx9da4
wants to merge
12
commits into
main
Choose a base branch
from
feat/incremental-pr-commits
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6e7f070
5f5a5b5
313714b
3445ead
b20f82d
d784e28
7c61ab8
643751a
+85 -42 environment.go and git.go
mfbx9da4 d311d9c
+5 -2 git.go
mfbx9da4 88e26c3
+11 -13 environment.go and git.go
mfbx9da4 f16e829
+13 -0 workflow-executor.yaml, Makefile and action.yml
mfbx9da4 5c55bcb
+6 -0 pr-mode-granular-commits.env
mfbx9da4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,32 +370,45 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act | |
|
||
logging.Info("Commit and pushing changes to git") | ||
|
||
if err := g.Add("."); err != nil { | ||
return "", fmt.Errorf("error adding changes: %w", err) | ||
catchAllCommitMessage := "feat: regenerated with Speakeasy CLI" | ||
if action == environment.ActionSuggest { | ||
catchAllCommitMessage = "feat: suggestions for OpenAPI spec" | ||
} | ||
|
||
var commitMessage string | ||
if action == environment.ActionRunWorkflow { | ||
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) | ||
commits := []struct { | ||
paths []string | ||
msg string | ||
}{ | ||
{paths: []string{"**/.speakeasy/", "*gen.yaml", "*gen.lock", "*workflow.yaml", "*workflow.lock"}, msg: "build: Speakeasy config and lock files"}, | ||
{paths: []string{"*.md"}, msg: "docs: regenerate markdown files"}, | ||
{paths: []string{"."}, msg: catchAllCommitMessage}, | ||
} | ||
|
||
// Create commit message | ||
if !environment.GetSignedCommits() { | ||
commitHash, err := w.Commit(commitMessage, &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: "speakeasybot", | ||
Email: "[email protected]", | ||
When: time.Now(), | ||
}, | ||
All: true, | ||
}) | ||
if err != nil { | ||
return "", fmt.Errorf("error committing changes: %w", err) | ||
var err error | ||
|
||
var lastCommitHash plumbing.Hash | ||
for _, 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()) | ||
} | ||
} | ||
|
||
h, err := w.Commit(commit.msg, &git.CommitOptions{ | ||
Author: &object.Signature{ | ||
Name: "speakeasybot", | ||
Email: "[email protected]", | ||
When: time.Now(), | ||
}, | ||
AllowEmptyCommits: false, | ||
All: commit.msg == catchAllCommitMessage, | ||
}) | ||
if err != nil { | ||
logging.Info(fmt.Errorf("unable to commit changes for %v: %w", commit.paths, err).Error()) | ||
} else { | ||
lastCommitHash = h | ||
} | ||
} | ||
|
||
if err := g.repo.Push(&git.PushOptions{ | ||
|
@@ -404,7 +417,13 @@ func (g *Git) CommitAndPush(openAPIDocVersion, speakeasyVersion, doc string, act | |
}); err != nil { | ||
return "", pushErr(err) | ||
} | ||
return commitHash.String(), nil | ||
return lastCommitHash.String(), nil | ||
} | ||
|
||
// ---- START Signed commits ---- | ||
// TODO: Due to priority constraints we don't split up into multiple commits like we do above | ||
if err := g.Add("."); err != nil { | ||
return "", fmt.Errorf("error adding changes: %w", err) | ||
} | ||
|
||
branch, err := g.GetCurrentBranch() | ||
|
@@ -447,7 +466,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(catchAllCommitMessage), | ||
Tree: &github.Tree{SHA: tree.SHA}, | ||
Parents: []*github.Commit{parentCommit}}, &github.CreateCommitOptions{}) | ||
if err != nil { | ||
|
@@ -520,6 +539,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) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
INPUT_MODE="pr" | ||
INPUT_LANGUAGES="- go" | ||
GITHUB_REPOSITORY="speakeasy-api/sdk-generation-action-test-repo" | ||
INPUT_FORCE=true | ||
RUN_FINALIZE=true | ||
INPUT_SIGNED_COMMITS=true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.