Skip to content
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

Add missing attribute to project push rules #1921

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions projects.go
Expand Up @@ -1570,6 +1570,7 @@ type ProjectPushRules struct {
FileNameRegex string `json:"file_name_regex"`
MaxFileSize int `json:"max_file_size"`
CommitCommitterCheck bool `json:"commit_committer_check"`
CommitCommitterNameCheck bool `json:"commit_committer_name_check"`
RejectUnsignedCommits bool `json:"reject_unsigned_commits"`
}

Expand Down Expand Up @@ -1607,6 +1608,7 @@ type AddProjectPushRuleOptions struct {
AuthorEmailRegex *string `url:"author_email_regex,omitempty" json:"author_email_regex,omitempty"`
BranchNameRegex *string `url:"branch_name_regex,omitempty" json:"branch_name_regex,omitempty"`
CommitCommitterCheck *bool `url:"commit_committer_check,omitempty" json:"commit_committer_check,omitempty"`
CommitCommitterNameCheck *bool `url:"commit_committer_name_check,omitempty" json:"commit_committer_name_check,omitempty"`
CommitMessageNegativeRegex *string `url:"commit_message_negative_regex,omitempty" json:"commit_message_negative_regex,omitempty"`
CommitMessageRegex *string `url:"commit_message_regex,omitempty" json:"commit_message_regex,omitempty"`
DenyDeleteTag *bool `url:"deny_delete_tag,omitempty" json:"deny_delete_tag,omitempty"`
Expand Down Expand Up @@ -1651,6 +1653,7 @@ type EditProjectPushRuleOptions struct {
AuthorEmailRegex *string `url:"author_email_regex,omitempty" json:"author_email_regex,omitempty"`
BranchNameRegex *string `url:"branch_name_regex,omitempty" json:"branch_name_regex,omitempty"`
CommitCommitterCheck *bool `url:"commit_committer_check,omitempty" json:"commit_committer_check,omitempty"`
CommitCommitterNameCheck *bool `url:"commit_committer_name_check,omitempty" json:"commit_committer_name_check,omitempty"`
CommitMessageNegativeRegex *string `url:"commit_message_negative_regex,omitempty" json:"commit_message_negative_regex,omitempty"`
CommitMessageRegex *string `url:"commit_message_regex,omitempty" json:"commit_message_regex,omitempty"`
DenyDeleteTag *bool `url:"deny_delete_tag,omitempty" json:"deny_delete_tag,omitempty"`
Expand Down
174 changes: 174 additions & 0 deletions projects_test.go
Expand Up @@ -1529,3 +1529,177 @@ func TestProjectEditWebhook_CustomTemplate(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, true, customWebhookSet)
}

func TestGetProjectPushRules(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/push_rule", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{
"id": 1,
"commit_message_regex": "Fixes \\d+\\..*",
"commit_message_negative_regex": "ssh\\:\\/\\/",
"branch_name_regex": "(feat|fix)\\/*",
"deny_delete_tag": false,
"member_check": false,
"prevent_secrets": false,
"author_email_regex": "@company.com$",
"file_name_regex": "(jar|exe)$",
"max_file_size": 5,
"commit_committer_check": false,
"commit_committer_name_check": false,
"reject_unsigned_commits": false
}`)
})

rule, _, err := client.Projects.GetProjectPushRules(1)
if err != nil {
t.Errorf("Projects.GetProjectPushRules returned error: %v", err)
}

want := &ProjectPushRules{
ID: 1,
CommitMessageRegex: "Fixes \\d+\\..*",
CommitMessageNegativeRegex: "ssh\\:\\/\\/",
BranchNameRegex: "(feat|fix)\\/*",
DenyDeleteTag: false,
MemberCheck: false,
PreventSecrets: false,
AuthorEmailRegex: "@company.com$",
FileNameRegex: "(jar|exe)$",
MaxFileSize: 5,
CommitCommitterCheck: false,
CommitCommitterNameCheck: false,
RejectUnsignedCommits: false,
}

if !reflect.DeepEqual(want, rule) {
t.Errorf("Projects.GetProjectPushRules returned %+v, want %+v", rule, want)
}
}

func TestAddProjectPushRules(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/push_rule", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{
"id": 1,
"commit_message_regex": "Fixes \\d+\\..*",
"commit_message_negative_regex": "ssh\\:\\/\\/",
"branch_name_regex": "(feat|fix)\\/*",
"deny_delete_tag": false,
"member_check": false,
"prevent_secrets": false,
"author_email_regex": "@company.com$",
"file_name_regex": "(jar|exe)$",
"max_file_size": 5,
"commit_committer_check": false,
"commit_committer_name_check": false,
"reject_unsigned_commits": false
}`)
})

opt := &AddProjectPushRuleOptions{
CommitMessageRegex: Ptr("Fixes \\d+\\..*"),
CommitMessageNegativeRegex: Ptr("ssh\\:\\/\\/"),
BranchNameRegex: Ptr("(feat|fix)\\/*"),
DenyDeleteTag: Ptr(false),
MemberCheck: Ptr(false),
PreventSecrets: Ptr(false),
AuthorEmailRegex: Ptr("@company.com$"),
FileNameRegex: Ptr("(jar|exe)$"),
MaxFileSize: Ptr(5),
CommitCommitterCheck: Ptr(false),
CommitCommitterNameCheck: Ptr(false),
RejectUnsignedCommits: Ptr(false),
}

rule, _, err := client.Projects.AddProjectPushRule(1, opt)
if err != nil {
t.Errorf("Projects.AddProjectPushRule returned error: %v", err)
}

want := &ProjectPushRules{
ID: 1,
CommitMessageRegex: "Fixes \\d+\\..*",
CommitMessageNegativeRegex: "ssh\\:\\/\\/",
BranchNameRegex: "(feat|fix)\\/*",
DenyDeleteTag: false,
MemberCheck: false,
PreventSecrets: false,
AuthorEmailRegex: "@company.com$",
FileNameRegex: "(jar|exe)$",
MaxFileSize: 5,
CommitCommitterCheck: false,
CommitCommitterNameCheck: false,
RejectUnsignedCommits: false,
}

if !reflect.DeepEqual(want, rule) {
t.Errorf("Projects.AddProjectPushRule returned %+v, want %+v", rule, want)
}
}

func TestEditProjectPushRules(t *testing.T) {
mux, client := setup(t)

mux.HandleFunc("/api/v4/projects/1/push_rule", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
fmt.Fprint(w, `{
"id": 1,
"commit_message_regex": "Fixes \\d+\\..*",
"commit_message_negative_regex": "ssh\\:\\/\\/",
"branch_name_regex": "(feat|fix)\\/*",
"deny_delete_tag": false,
"member_check": false,
"prevent_secrets": false,
"author_email_regex": "@company.com$",
"file_name_regex": "(jar|exe)$",
"max_file_size": 5,
"commit_committer_check": false,
"commit_committer_name_check": false,
"reject_unsigned_commits": false
}`)
})

opt := &EditProjectPushRuleOptions{
CommitMessageRegex: Ptr("Fixes \\d+\\..*"),
CommitMessageNegativeRegex: Ptr("ssh\\:\\/\\/"),
BranchNameRegex: Ptr("(feat|fix)\\/*"),
DenyDeleteTag: Ptr(false),
MemberCheck: Ptr(false),
PreventSecrets: Ptr(false),
AuthorEmailRegex: Ptr("@company.com$"),
FileNameRegex: Ptr("(jar|exe)$"),
MaxFileSize: Ptr(5),
CommitCommitterCheck: Ptr(false),
CommitCommitterNameCheck: Ptr(false),
RejectUnsignedCommits: Ptr(false),
}

rule, _, err := client.Projects.EditProjectPushRule(1, opt)
if err != nil {
t.Errorf("Projects.EditProjectPushRule returned error: %v", err)
}

want := &ProjectPushRules{
ID: 1,
CommitMessageRegex: "Fixes \\d+\\..*",
CommitMessageNegativeRegex: "ssh\\:\\/\\/",
BranchNameRegex: "(feat|fix)\\/*",
DenyDeleteTag: false,
MemberCheck: false,
PreventSecrets: false,
AuthorEmailRegex: "@company.com$",
FileNameRegex: "(jar|exe)$",
MaxFileSize: 5,
CommitCommitterCheck: false,
CommitCommitterNameCheck: false,
RejectUnsignedCommits: false,
}

if !reflect.DeepEqual(want, rule) {
t.Errorf("Projects.EditProjectPushRule returned %+v, want %+v", rule, want)
}
}