Skip to content

Commit

Permalink
added support for github visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Dec 17, 2020
1 parent ffa46d9 commit 5141b8e
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 58 deletions.
25 changes: 25 additions & 0 deletions scm/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,28 @@ func (k *ContentKind) UnmarshalJSON(data []byte) error {
}
return nil
}

// Visibility defines repository visibility.
type Visibility int

// Role values.
const (
VisibilityUndefined Visibility = iota
VisibilityPublic
VisibilityInternal
VisibilityPrivate
)

// String returns the string representation of Role.
func (v Visibility) String() (s string) {
switch v {
case VisibilityPublic:
return "public"
case VisibilityInternal:
return "internal"
case VisibilityPrivate:
return "private"
default:
return "unknown"
}
}
29 changes: 22 additions & 7 deletions scm/driver/github/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type repository struct {
FullName string `json:"full_name"`
Private bool `json:"private"`
Fork bool `json:"fork"`
Visibility string `json:"visibility"`
HTMLURL string `json:"html_url"`
SSHURL string `json:"ssh_url"`
CloneURL string `json:"clone_url"`
Expand Down Expand Up @@ -202,13 +203,14 @@ func convertRepository(from *repository) *scm.Repository {
Pull: from.Permissions.Pull,
Admin: from.Permissions.Admin,
},
Link: from.HTMLURL,
Branch: from.DefaultBranch,
Private: from.Private,
Clone: from.CloneURL,
CloneSSH: from.SSHURL,
Created: from.CreatedAt,
Updated: from.UpdatedAt,
Link: from.HTMLURL,
Branch: from.DefaultBranch,
Private: from.Private,
Visibility: convertVisibility(from.Visibility),
Clone: from.CloneURL,
CloneSSH: from.SSHURL,
Created: from.CreatedAt,
Updated: from.UpdatedAt,
}
}

Expand Down Expand Up @@ -257,6 +259,19 @@ func convertFromHookEvents(from scm.HookEvents) []string {
return events
}

func convertVisibility(from string) scm.Visibility {
switch from {
case "public":
return scm.VisibilityPublic
case "private":
return scm.VisibilityPrivate
case "internal":
return scm.VisibilityInternal
default:
return scm.VisibilityUndefined
}
}

type status struct {
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/repo.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"description": "This your first repo!",
"private": true,
"fork": false,
"visibility": "public",
"url": "https://api.github.com/repos/octocat/Hello-World",
"html_url": "https://github.com/octocat/Hello-World",
"archive_url": "http:https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/repo.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"Branch": "master",
"Private": true,
"Visibility": 1,
"Clone": "https://github.com/octocat/Hello-World.git",
"CloneSSH": "[email protected]:octocat/Hello-World.git",
"Link": "https://github.com/octocat/Hello-World",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/repos.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"description": "This your first repo!",
"private": true,
"fork": true,
"visibility": "public",
"url": "https://api.github.com/repos/octocat/Hello-World",
"html_url": "https://github.com/octocat/Hello-World",
"archive_url": "http:https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/repos.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"Branch": "master",
"Private": true,
"Visibility": 1,
"Clone": "https://github.com/octocat/Hello-World.git",
"CloneSSH": "[email protected]:octocat/Hello-World.git",
"Link": "https://github.com/octocat/Hello-World",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/webhooks/tag_create.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"site_admin": false
},
"private": true,
"visibility": "private",
"html_url": "https://github.com/bradrydzewski/drone-test-go",
"description": "test project written in Go",
"fork": true,
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/webhooks/tag_create.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Perm": null,
"Branch": "master",
"Private": true,
"Visibility": 3,
"Clone": "https://github.com/bradrydzewski/drone-test-go.git",
"CloneSSH": "[email protected]:bradrydzewski/drone-test-go.git",
"Link": "https://github.com/bradrydzewski/drone-test-go",
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/webhooks/tag_delete.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"site_admin": false
},
"private": true,
"visibility": "internal",
"html_url": "https://github.com/bradrydzewski/drone-test-go",
"description": "test project written in Go",
"fork": true,
Expand Down
1 change: 1 addition & 0 deletions scm/driver/github/testdata/webhooks/tag_delete.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"Perm": null,
"Branch": "master",
"Private": true,
"Visibility": 2,
"Clone": "https://github.com/bradrydzewski/drone-test-go.git",
"CloneSSH": "[email protected]:bradrydzewski/drone-test-go.git",
"Link": "https://github.com/bradrydzewski/drone-test-go",
Expand Down
86 changes: 46 additions & 40 deletions scm/driver/github/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ type (
Name string `json:"name"`
FullName string `json:"full_name"`
Private bool `json:"private"`
Visibility string `json:"visibility"`
Fork bool `json:"fork"`
HTMLURL string `json:"html_url"`
SSHURL string `json:"ssh_url"`
Expand Down Expand Up @@ -310,14 +311,15 @@ func convertPushHook(src *pushHook) *scm.PushHook {
},
},
Repo: scm.Repository{
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Visibility: convertVisibility(src.Repository.Visibility),
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
},
Sender: *convertUser(&src.Sender),
Commits: commits,
Expand All @@ -336,14 +338,15 @@ func convertBranchHook(src *createDeleteHook) *scm.BranchHook {
Name: src.Ref,
},
Repo: scm.Repository{
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Visibility: convertVisibility(src.Repository.Visibility),
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
},
Sender: *convertUser(&src.Sender),
}
Expand All @@ -355,14 +358,15 @@ func convertTagHook(src *createDeleteHook) *scm.TagHook {
Name: src.Ref,
},
Repo: scm.Repository{
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Visibility: convertVisibility(src.Repository.Visibility),
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
},
Sender: *convertUser(&src.Sender),
}
Expand All @@ -372,14 +376,15 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
return &scm.PullRequestHook{
// Action Action
Repo: scm.Repository{
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Visibility: convertVisibility(src.Repository.Visibility),
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
},
PullRequest: *convertPullRequest(&src.PullRequest),
Sender: *convertUser(&src.Sender),
Expand All @@ -397,14 +402,15 @@ func convertDeploymentHook(src *deploymentHook) *scm.DeployHook {
Sha: src.Deployment.Sha.String,
},
Repo: scm.Repository{
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
ID: fmt.Sprint(src.Repository.ID),
Namespace: src.Repository.Owner.Login,
Name: src.Repository.Name,
Branch: src.Repository.DefaultBranch,
Private: src.Repository.Private,
Visibility: convertVisibility(src.Repository.Visibility),
Clone: src.Repository.CloneURL,
CloneSSH: src.Repository.SSHURL,
Link: src.Repository.HTMLURL,
},
Sender: *convertUser(&src.Sender),
Task: src.Deployment.Task.String,
Expand Down
23 changes: 12 additions & 11 deletions scm/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import (
type (
// Repository represents a git repository.
Repository struct {
ID string
Namespace string
Name string
Perm *Perm
Branch string
Private bool
Clone string
CloneSSH string
Link string
Created time.Time
Updated time.Time
ID string
Namespace string
Name string
Perm *Perm
Branch string
Private bool
Visibility Visibility
Clone string
CloneSSH string
Link string
Created time.Time
Updated time.Time
}

// Perm represents a user's repository permissions.
Expand Down

0 comments on commit 5141b8e

Please sign in to comment.