-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add optional, org-wide Gitpod commit annotation #20525
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f7e9b1c
[supervisor] Add Gitpod commit annotation
filiptronicek b131e0e
server and API changes
filiptronicek 25ec9e9
[dashboard] add org setting for commit annotation
filiptronicek eefd3cf
Fix things
filiptronicek 841f75e
Fix label for annotation switch
filiptronicek e425acc
Revert accidental rename
filiptronicek 057bffc
minor docs fixes
filiptronicek 592d324
Add a feature flag for the setting: `commit_annotation_setting_enabled`
filiptronicek 607a509
Register hook in the cloned repo instead of under /etc/
filiptronicek ec1be43
don't override existing hooks
filiptronicek 7ccd1c8
`gp git-commit-message-helper` to use `git interpret-trailers`
filiptronicek bab3949
Test it!
filiptronicek 5147432
🧹 indeed
filiptronicek 2deac15
Merge remote-tracking branch 'origin/main' into ft/org-gitpod-commit-…
filiptronicek 6e6b37a
Update timestamp of DB migration
filiptronicek 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
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 |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
| // Licensed under the GNU Affero General Public License (AGPL). | ||
| // See License.AGPL.txt in the project root for license information. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/exec" | ||
| "time" | ||
|
|
||
| "github.com/gitpod-io/gitpod/gitpod-cli/pkg/gitpod" | ||
| log "github.com/sirupsen/logrus" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var gitCommitMessageHelperOpts struct { | ||
| CommitMessageFile string | ||
| } | ||
|
|
||
| func addGitpodTrailer(commitMsgFile string, hostName string) error { | ||
| trailerCmd := exec.Command("git", "interpret-trailers", | ||
| "--if-exists", "addIfDifferent", | ||
| "--trailer", fmt.Sprintf("Tool: gitpod/%s", hostName), | ||
| commitMsgFile) | ||
|
|
||
| output, err := trailerCmd.Output() | ||
| if err != nil { | ||
| return fmt.Errorf("error adding trailer: %w", err) | ||
| } | ||
|
|
||
| err = os.WriteFile(commitMsgFile, output, 0644) | ||
| if err != nil { | ||
| return fmt.Errorf("error writing commit message file: %w", err) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| var gitCommitMessageHelper = &cobra.Command{ | ||
| Use: "git-commit-message-helper", | ||
| Short: "Gitpod's Git commit message helper", | ||
| Long: "Automatically adds Tool information to Git commit messages", | ||
| Args: cobra.ExactArgs(0), | ||
| Hidden: true, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| ctx, cancel := context.WithTimeout(cmd.Context(), 5*time.Second) | ||
| defer cancel() | ||
|
|
||
| wsInfo, err := gitpod.GetWSInfo(ctx) | ||
| if err != nil { | ||
| log.WithError(err).Fatal("error getting workspace info") | ||
| return nil // don't block commit | ||
| } | ||
|
|
||
| if err := addGitpodTrailer(gitCommitMessageHelperOpts.CommitMessageFile, wsInfo.GitpodApi.Host); err != nil { | ||
| log.WithError(err).Fatal("failed to add gitpod trailer") | ||
| return nil // don't block commit | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(gitCommitMessageHelper) | ||
| gitCommitMessageHelper.Flags().StringVarP(&gitCommitMessageHelperOpts.CommitMessageFile, "file", "f", "", "Path to the commit message file") | ||
| _ = gitCommitMessageHelper.MarkFlagRequired("file") | ||
| } |
74 changes: 74 additions & 0 deletions
74
components/gitpod-cli/cmd/git-commit-message-helper_test.go
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,74 @@ | ||
| // Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
| // Licensed under the GNU Affero General Public License (AGPL). | ||
| // See License.AGPL.txt in the project root for license information. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/google/go-cmp/cmp" | ||
| ) | ||
|
|
||
| func TestAddGitpodTrailer(t *testing.T) { | ||
| tests := []struct { | ||
| Name string | ||
| CommitMsg string | ||
| HostName string | ||
| Expected string | ||
| ExpectError bool | ||
| }{ | ||
| { | ||
| Name: "adds trailer to simple message", | ||
| CommitMsg: "Initial commit", | ||
| HostName: "gitpod.io", | ||
| Expected: "Initial commit\n\nTool: gitpod/gitpod.io\n", | ||
| ExpectError: false, | ||
| }, | ||
| { | ||
| Name: "doesn't duplicate existing trailer", | ||
| CommitMsg: "Initial commit\n\nTool: gitpod/gitpod.io\n", | ||
| HostName: "gitpod.io", | ||
| Expected: "Initial commit\n\nTool: gitpod/gitpod.io\n", | ||
| ExpectError: false, | ||
| }, | ||
| { | ||
| Name: "preserves other trailers", | ||
| CommitMsg: "Initial commit\n\nSigned-off-by: Kyle <[email protected]>\n", | ||
| HostName: "gitpod.io", | ||
| Expected: "Initial commit\n\nSigned-off-by: Kyle <[email protected]>\nTool: gitpod/gitpod.io\n", | ||
| ExpectError: false, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.Name, func(t *testing.T) { | ||
| tmpfile, err := os.CreateTemp("", "commit-msg-*") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| defer os.Remove(tmpfile.Name()) | ||
|
|
||
| if err := os.WriteFile(tmpfile.Name(), []byte(tt.CommitMsg), 0644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| err = addGitpodTrailer(tmpfile.Name(), tt.HostName) | ||
| if (err != nil) != tt.ExpectError { | ||
| t.Errorf("addGitpodTrailer() error = %v, wantErr %v", err, tt.ExpectError) | ||
| return | ||
| } | ||
|
|
||
| got, err := os.ReadFile(tmpfile.Name()) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| equal := cmp.Equal(string(got), tt.Expected) | ||
| if !equal { | ||
| t.Fatalf(`Detected git command info was incorrect, got: %v, expected: %v.`, string(got), tt.Expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
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
25 changes: 25 additions & 0 deletions
25
components/gitpod-db/src/typeorm/migration/1736951418625-AddOrgSettingsCommitAnnotation.ts
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,25 @@ | ||
| /** | ||
| * Copyright (c) 2025 Gitpod GmbH. All rights reserved. | ||
| * Licensed under the GNU Affero General Public License (AGPL). | ||
| * See License.AGPL.txt in the project root for license information. | ||
| */ | ||
|
|
||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
| import { columnExists } from "./helper/helper"; | ||
|
|
||
| const table = "d_b_org_settings"; | ||
| const newColumn = "annotateGitCommits"; | ||
|
|
||
| export class AddOrgSettingsCommitAnnotation1736951418625 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| if (!(await columnExists(queryRunner, table, newColumn))) { | ||
| await queryRunner.query(`ALTER TABLE ${table} ADD COLUMN ${newColumn} BOOLEAN DEFAULT FALSE`); | ||
| } | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| if (await columnExists(queryRunner, table, newColumn)) { | ||
| await queryRunner.query(`ALTER TABLE ${table} DROP COLUMN ${newColumn}`); | ||
| } | ||
| } | ||
| } |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, how we indicate what kind of settings should be on
GeneralandPolicies? (I was trying to find this setting on Policies tab before look through the code)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mustard-mh I generally go with my gut here. This time around, I didn't consider this feature a policy, since it's not restricting anything per se, like our other policies we have on that page.
It could definitely be argued that "it's asserting that all of an organization's commits have our
Tool:trailer", though, so maybe? What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a strong opinion there, just curious 😋 Any place is good for me (Once the docs to the user is clear, and for sure you will do it)