Skip to content

Commit 6da1e07

Browse files
committed
fix(gitlab): remove custom author when commit signing is enabled
1 parent faee514 commit 6da1e07

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

gitlab2sentry/resources.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
import os
21
from collections import namedtuple
32
from typing import List, Tuple
43
from pydantic import Field
54
from pydantic_settings import BaseSettings
65

7-
ENV = os.getenv("ENV", "production")
8-
96

107
class Settings(BaseSettings):
118
env: str = Field("production")
@@ -26,7 +23,9 @@ class Settings(BaseSettings):
2623
project = {project_slug}
2724
""")
2825
dsn_branch_name: str = Field("auto_add_sentry_dsn")
29-
dsn_mr_title: str = Field("[gitlab2sentry] Merge me to add your Sentry DSN to {project_name}")
26+
dsn_mr_title: str = Field(
27+
"[gitlab2sentry] Merge me to add your Sentry DSN to {project_name}"
28+
)
3029
dsn_mr_description: str = Field("""
3130
{mentions} Congrats, your Sentry project has been
3231
created, merge this
@@ -41,7 +40,9 @@ class Settings(BaseSettings):
4140
url = {sentry_url}
4241
""")
4342
sentryclirc_branch_name: str = Field("auto_add_sentry")
44-
sentryclirc_mr_title: str = Field("[gitlab2sentry] Merge me to add Sentry to {project_name} or close me")
43+
sentryclirc_mr_title: str = Field(
44+
"[gitlab2sentry] Merge me to add Sentry to {project_name} or close me"
45+
)
4546
sentryclirc_filepath: str = Field(".sentryclirc")
4647
sentryclirc_com_msg: str = Field("Update .sentryclirc")
4748
sentryclirc_mr_description: str = Field("""
@@ -65,9 +66,10 @@ class Settings(BaseSettings):
6566
gitlab_rmv_src_branch: bool = Field(True)
6667
gitlab_token: str = Field("default-token")
6768
gitlab_url: str = Field("http://default-gitlab-url")
69+
gitlab_signed_commit: bool = Field(False)
6870

6971

70-
settings = Settings() # type: ignore
72+
settings = Settings() # type: ignore
7173

7274
# G2SProject namedtuple configuration
7375
G2SProject = namedtuple(

gitlab2sentry/utils/gitlab_provider.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,20 @@ def _get_or_create_sentryclirc(
181181
full_path,
182182
)
183183
)
184-
f = project.files.create(
185-
{
184+
data = {
186185
"author_email": settings.gitlab_author_email,
187186
"author_name": settings.gitlab_author_name,
188187
"branch": branch_name,
189188
"commit_message": settings.sentryclirc_com_msg,
190189
"content": content,
191190
"file_path": file_path,
192191
}
193-
)
192+
# When commit signing is enabled in GitLab (e.g. via pre-hook), commit signing requires that the author information matches the identity of the signer.
193+
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/150855
194+
if settings.gitlab_signed_commit:
195+
data.pop("author_email")
196+
data.pop("author_name")
197+
f = project.files.create(data=data)
194198

195199
def _get_default_mentions(self, project: Project) -> str:
196200
return ", ".join(

0 commit comments

Comments
 (0)