+
Skip to content

Support Github Advanced Security repository settings #2133

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 3 commits into from
Oct 20, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions github/github-accessors.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions github/github-accessors_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 33 additions & 1 deletion github/github-stringify_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions github/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ type Repository struct {
LicenseTemplate *string `json:"license_template,omitempty"`
GitignoreTemplate *string `json:"gitignore_template,omitempty"`

// Options for configuring Advanced Security and Secret Scanning
SecurityAndAnalysis *SecurityAndAnalysis `json:"security_and_analysis,omitempty"`

// Creating an organization repository. Required for non-owners.
TeamID *int64 `json:"team_id,omitempty"`

Expand Down Expand Up @@ -183,6 +186,39 @@ type RepositoryListOptions struct {
ListOptions
}

// SecurityAndAnalysis specifies the optional advanced security features
// that are enabled on a given repository.
type SecurityAndAnalysis struct {
AdvancedSecurity *AdvancedSecurity `json:"advanced_security,omitempty"`
SecretScanning *SecretScanning `json:"secret_scanning,omitempty"`
}

func (s SecurityAndAnalysis) String() string {
return Stringify(s)
}

// AdvancedSecurity specifies the state of advanced security on a repository.
//
// GitHub API docs: https://docs.github.com/en/github/getting-started-with-github/learning-about-github/about-github-advanced-security
type AdvancedSecurity struct {
Status *string `json:"status,omitempty"`
}

func (a AdvancedSecurity) String() string {
return Stringify(a)
}

// SecretScanning specifies the state of secret scanning on a repository.
//
// GitHub API docs: https://docs.github.com/en/code-security/secret-security/about-secret-scanning
type SecretScanning struct {
Status *string `json:"status,omitempty"`
}

func (s SecretScanning) String() string {
return Stringify(s)
}

// List the repositories for a user. Passing the empty string will list
// repositories for the authenticated user.
//
Expand Down
4 changes: 2 additions & 2 deletions github/repos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func TestRepositoriesService_Get(t *testing.T) {
mux.HandleFunc("/repos/o/r", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"}}`)
fmt.Fprint(w, `{"id":1,"name":"n","description":"d","owner":{"login":"l"},"license":{"key":"mit"},"security_and_analysis":{"advanced_security":{"status":"enabled"},"secret_scanning":{"status":"enabled"}}}`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if there is a better place for this, or if you'd like a separate test.

})

ctx := context.Background()
Expand All @@ -369,7 +369,7 @@ func TestRepositoriesService_Get(t *testing.T) {
t.Errorf("Repositories.Get returned error: %v", err)
}

want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}}
want := &Repository{ID: Int64(1), Name: String("n"), Description: String("d"), Owner: &User{Login: String("l")}, License: &License{Key: String("mit")}, SecurityAndAnalysis: &SecurityAndAnalysis{AdvancedSecurity: &AdvancedSecurity{Status: String("enabled")}, SecretScanning: &SecretScanning{String("enabled")}}}
if !cmp.Equal(got, want) {
t.Errorf("Repositories.Get returned %+v, want %+v", got, want)
}
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载