This repository has been archived by the owner on Dec 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1916 from vntw/access-token-webhook-event
Add new project and group access token events to webhook event types
- Loading branch information
Showing
6 changed files
with
284 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -286,6 +286,48 @@ func TestFeatureFlagEventUnmarshal(t *testing.T) { | |
} | ||
} | ||
|
||
func TestGroupResourceAccessTokenEventUnmarshal(t *testing.T) { | ||
jsonObject := loadFixture("testdata/webhooks/resource_access_token_group.json") | ||
var event *GroupResourceAccessTokenEvent | ||
err := json.Unmarshal(jsonObject, &event) | ||
if err != nil { | ||
t.Errorf("could not unmarshal event: %v\n ", err.Error()) | ||
} | ||
|
||
if event == nil { | ||
t.Errorf("event is null") | ||
} | ||
|
||
createdAt, err := time.Parse(time.RFC3339, "2024-02-05T03:13:44.855Z") | ||
if err != nil { | ||
t.Fatalf("could not parse time: %v", err) | ||
} | ||
|
||
expiresAt, err := ParseISOTime("2024-01-26") | ||
if err != nil { | ||
t.Fatalf("could not parse ISO time: %v", err) | ||
} | ||
|
||
expected := &GroupResourceAccessTokenEvent{ | ||
GroupID: 35, | ||
ObjectKind: "access_token", | ||
EventName: "expiring_access_token", | ||
} | ||
|
||
expected.Group.GroupID = 35 | ||
expected.Group.GroupName = "Twitter" | ||
expected.Group.GroupPath = "twitter" | ||
expected.Group.FullPath = "twitter" | ||
|
||
expected.ObjectAttributes.ID = 25 | ||
expected.ObjectAttributes.UserID = 90 | ||
expected.ObjectAttributes.Name = "acd" | ||
expected.ObjectAttributes.CreatedAt = &createdAt | ||
expected.ObjectAttributes.ExpiresAt = &expiresAt | ||
|
||
assert.Equal(t, expected, event) | ||
} | ||
|
||
func TestIssueCommentEventUnmarshal(t *testing.T) { | ||
jsonObject := loadFixture("testdata/webhooks/note_issue.json") | ||
|
||
|
@@ -1014,6 +1056,60 @@ func TestPipelineEventUnmarshal(t *testing.T) { | |
} | ||
} | ||
|
||
func TestProjectResourceAccessTokenEventUnmarshal(t *testing.T) { | ||
jsonObject := loadFixture("testdata/webhooks/resource_access_token_project.json") | ||
var event *ProjectResourceAccessTokenEvent | ||
err := json.Unmarshal(jsonObject, &event) | ||
if err != nil { | ||
t.Errorf("could not unmarshal event: %v\n ", err.Error()) | ||
} | ||
|
||
if event == nil { | ||
t.Errorf("event is null") | ||
} | ||
|
||
createdAt, err := time.Parse(time.RFC3339, "2024-02-05T03:13:44.855Z") | ||
if err != nil { | ||
t.Fatalf("could not parse time: %v", err) | ||
} | ||
|
||
expiresAt, err := ParseISOTime("2024-01-26") | ||
if err != nil { | ||
t.Fatalf("could not parse ISO time: %v", err) | ||
} | ||
|
||
expected := &ProjectResourceAccessTokenEvent{ | ||
ProjectID: 7, | ||
ObjectKind: "access_token", | ||
EventName: "expiring_access_token", | ||
} | ||
|
||
expected.ObjectAttributes.ID = 25 | ||
expected.ObjectAttributes.UserID = 90 | ||
expected.ObjectAttributes.Name = "acd" | ||
expected.ObjectAttributes.CreatedAt = &createdAt | ||
expected.ObjectAttributes.ExpiresAt = &expiresAt | ||
|
||
expected.Project.ID = 7 | ||
expected.Project.Name = "Flight" | ||
expected.Project.Description = "Eum dolore maxime atque reprehenderit voluptatem." | ||
expected.Project.WebURL = "https://example.com/flightjs/Flight" | ||
expected.Project.AvatarURL = "" | ||
expected.Project.GitSSHURL = "ssh://[email protected]/flightjs/Flight.git" | ||
expected.Project.GitHTTPURL = "https://example.com/flightjs/Flight.git" | ||
expected.Project.Namespace = "Flightjs" | ||
expected.Project.VisibilityLevel = 0 | ||
expected.Project.PathWithNamespace = "flightjs/Flight" | ||
expected.Project.DefaultBranch = "master" | ||
expected.Project.CIConfigPath = "" | ||
expected.Project.Homepage = "https://example.com/flightjs/Flight" | ||
expected.Project.URL = "ssh://[email protected]/flightjs/Flight.git" | ||
expected.Project.SSHURL = "ssh://[email protected]/flightjs/Flight.git" | ||
expected.Project.HTTPURL = "https://example.com/flightjs/Flight.git" | ||
|
||
assert.Equal(t, expected, event) | ||
} | ||
|
||
func TestPushEventUnmarshal(t *testing.T) { | ||
jsonObject := loadFixture("testdata/webhooks/push.json") | ||
var event *PushEvent | ||
|
This file contains 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,18 @@ | ||
{ | ||
"object_kind": "access_token", | ||
"group_id": 35, | ||
"group": { | ||
"group_name": "Twitter", | ||
"group_path": "twitter", | ||
"full_path": "twitter", | ||
"group_id": 35 | ||
}, | ||
"object_attributes": { | ||
"user_id": 90, | ||
"created_at": "2024-02-05T03:13:44.855Z", | ||
"id": 25, | ||
"name": "acd", | ||
"expires_at": "2024-01-26" | ||
}, | ||
"event_name": "expiring_access_token" | ||
} |
This file contains 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,30 @@ | ||
{ | ||
"object_kind": "access_token", | ||
"project_id": 7, | ||
"project": { | ||
"id": 7, | ||
"name": "Flight", | ||
"description": "Eum dolore maxime atque reprehenderit voluptatem.", | ||
"web_url": "https://example.com/flightjs/Flight", | ||
"avatar_url": null, | ||
"git_ssh_url": "ssh://[email protected]/flightjs/Flight.git", | ||
"git_http_url": "https://example.com/flightjs/Flight.git", | ||
"namespace": "Flightjs", | ||
"visibility_level": 0, | ||
"path_with_namespace": "flightjs/Flight", | ||
"default_branch": "master", | ||
"ci_config_path": null, | ||
"homepage": "https://example.com/flightjs/Flight", | ||
"url": "ssh://[email protected]/flightjs/Flight.git", | ||
"ssh_url": "ssh://[email protected]/flightjs/Flight.git", | ||
"http_url": "https://example.com/flightjs/Flight.git" | ||
}, | ||
"object_attributes": { | ||
"user_id": 90, | ||
"created_at": "2024-02-05T03:13:44.855Z", | ||
"id": 25, | ||
"name": "acd", | ||
"expires_at": "2024-01-26" | ||
}, | ||
"event_name": "expiring_access_token" | ||
} |