[INS-258] Revert includeRepos removal from GitHub source (#4673)
* Revert "Remove include repos (#4469)"
This reverts commit 24c73b0cb6.
* generate protos
* preserve tests for repositories
This commit is contained in:
@@ -20,6 +20,7 @@ func (e *Engine) ScanGitHub(ctx context.Context, c sources.GithubConfig) (source
|
||||
Repositories: c.Repos,
|
||||
ScanUsers: c.IncludeMembers,
|
||||
IgnoreRepos: c.ExcludeRepos,
|
||||
IncludeRepos: c.IncludeRepos,
|
||||
IncludeForks: c.IncludeForks,
|
||||
IncludeIssueComments: c.IncludeIssueComments,
|
||||
IncludePullRequestComments: c.IncludePullRequestComments,
|
||||
|
||||
+543
-549
File diff suppressed because it is too large
Load Diff
@@ -254,7 +254,7 @@ func (s *Source) Init(aCtx context.Context, name string, jobID sources.JobID, so
|
||||
|
||||
s.filteredRepoCache = s.newFilteredRepoCache(aCtx,
|
||||
simple.NewCache[string](),
|
||||
s.conn.GetRepositories(),
|
||||
append(s.conn.GetRepositories(), s.conn.GetIncludeRepos()...),
|
||||
s.conn.GetIgnoreRepos(),
|
||||
)
|
||||
s.repos = s.conn.Repositories
|
||||
|
||||
@@ -142,6 +142,36 @@ func TestAddReposByOrg_Repositories(t *testing.T) {
|
||||
assert.True(t, gock.IsDone())
|
||||
}
|
||||
|
||||
func TestAddReposByOrg_IncludeRepos(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
gock.New("https://api.github.com").
|
||||
Get("/orgs/super-secret-org/repos").
|
||||
Reply(200).
|
||||
JSON(`[
|
||||
{"full_name": "super-secret-org/super-secret-repo", "clone_url": "https://github.com/super-secret-org/super-secret-repo.git", "size": 1},
|
||||
{"full_name": "super-secret-org/super-secret-repo2", "clone_url": "https://github.com/super-secret-org/super-secret-repo2.git", "size": 1},
|
||||
{"full_name": "super-secret-org/not-super-secret-repo", "clone_url": "https://github.com/super-secret-org/not-super-secret-repo.git", "size": 1}
|
||||
]`)
|
||||
|
||||
s := initTestSource(&sourcespb.GitHub{
|
||||
Credential: &sourcespb.GitHub_Token{
|
||||
Token: "super secret token",
|
||||
},
|
||||
IncludeRepos: []string{"super-secret-org/super*"},
|
||||
Organizations: []string{"super-secret-org"},
|
||||
})
|
||||
err := s.getReposByOrg(context.Background(), "super-secret-org", noopReporter())
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2, s.filteredRepoCache.Count())
|
||||
ok := s.filteredRepoCache.Exists("super-secret-org/super-secret-repo")
|
||||
assert.True(t, ok)
|
||||
ok = s.filteredRepoCache.Exists("super-secret-org/super-secret-repo2")
|
||||
assert.True(t, ok)
|
||||
assert.False(t, gock.HasUnmatchedRequest())
|
||||
assert.True(t, gock.IsDone())
|
||||
}
|
||||
|
||||
func TestAddReposByUser(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
@@ -773,6 +803,30 @@ func TestEnumerateWithToken_Repositories(t *testing.T) {
|
||||
assert.True(t, gock.IsDone())
|
||||
}
|
||||
|
||||
func TestEnumerateWithToken_IncludeRepos(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
gock.New("https://api.github.com").
|
||||
Get("/user").
|
||||
Reply(200).
|
||||
JSON(map[string]string{"login": "super-secret-user"})
|
||||
|
||||
s := initTestSource(&sourcespb.GitHub{
|
||||
Endpoint: "https://api.github.com",
|
||||
Credential: &sourcespb.GitHub_Token{
|
||||
Token: "token",
|
||||
},
|
||||
})
|
||||
s.repos = []string{"some-special-repo"}
|
||||
|
||||
err := s.enumerateWithToken(context.Background(), false, noopReporter())
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 1, len(s.repos))
|
||||
assert.Equal(t, []string{"some-special-repo"}, s.repos)
|
||||
assert.False(t, gock.HasUnmatchedRequest())
|
||||
assert.True(t, gock.IsDone())
|
||||
}
|
||||
|
||||
func TestEnumerateWithApp(t *testing.T) {
|
||||
defer gock.Off()
|
||||
|
||||
|
||||
+1
-4
@@ -266,10 +266,7 @@ message GitHub {
|
||||
string head = 9;
|
||||
string base = 10;
|
||||
repeated string ignore_repos = 11;
|
||||
// DEPRECATED: include_repos is deprecated in favor of repositories.
|
||||
// It was used for filtering when the repositories field wasn't populating the UI-input results correctly
|
||||
// It can be removed when we no longer depend on it
|
||||
repeated string include_repos = 12 [deprecated = true];
|
||||
repeated string include_repos = 12;
|
||||
bool include_pull_request_comments = 14;
|
||||
bool include_issue_comments = 15;
|
||||
bool include_gist_comments = 16;
|
||||
|
||||
Reference in New Issue
Block a user