Skip to content
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
44 changes: 36 additions & 8 deletions backend/plugins/github/api/remote_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func listGithubRemoteScopes(
}

if connection.AuthMethod == plugin.AUTH_METHOD_APPKEY {
return listGithubAppInstalledRepos(apiClient, page)
return listGithubAppInstalledRepos(apiClient, groupId, page)
}
if groupId == "" {
return listGithubUserOrgs(apiClient, page)
Expand Down Expand Up @@ -154,6 +154,7 @@ func listGithubOrgRepos(

func listGithubAppInstalledRepos(
apiClient plugin.ApiClient,
org string,
page GithubRemotePagination,
) (
children []dsmodels.DsRemoteApiScopeListEntry[models.GithubRepo],
Expand All @@ -170,21 +171,26 @@ func listGithubAppInstalledRepos(
if err != nil {
return nil, nil, err
}
var appRepos GithubAppRepo
var appRepos GithubAppRepoResult
errors.Must(api.UnmarshalResponse(resApp, &appRepos))
processedOrgs := make(map[string]struct{})
for _, r := range appRepos.Repositories {
orgName := r.Owner.Login
if _, exists := processedOrgs[orgName]; !exists && orgName != "" {
// Return only the unique orgs when org is not selected
if _, exists := processedOrgs[orgName]; !exists && orgName != "" && org == "" {
children = append(children, dsmodels.DsRemoteApiScopeListEntry[models.GithubRepo]{
Type: api.RAS_ENTRY_TYPE_SCOPE,
ParentId: &orgName,
Id: fmt.Sprintf("%v", r.ID),
Name: fmt.Sprintf("%v", r.Name),
FullName: fmt.Sprintf("%v", r.FullName),
Type: api.RAS_ENTRY_TYPE_GROUP,
ParentId: nil,
Id: fmt.Sprintf("%v", orgName),
Name: fmt.Sprintf("%v", orgName),
FullName: fmt.Sprintf("%v", orgName),
})
processedOrgs[orgName] = struct{}{}
}
// Return only repos when org is selected
if org != "" {
children = append(children, toGithubAppRepoModel(&r))
}
}
if len(appRepos.Repositories) == page.PerPage {
nextPage = &GithubRemotePagination{
Expand Down Expand Up @@ -249,6 +255,28 @@ func toRepoModel(r *repo) dsmodels.DsRemoteApiScopeListEntry[models.GithubRepo]
}
}

func toGithubAppRepoModel(r *GithubAppRepo) dsmodels.DsRemoteApiScopeListEntry[models.GithubRepo] {
parentId := fmt.Sprintf("%v", r.Owner.Login)
return dsmodels.DsRemoteApiScopeListEntry[models.GithubRepo]{
Type: api.RAS_ENTRY_TYPE_SCOPE,
ParentId: &parentId,
Id: fmt.Sprintf("%v", r.ID),
Name: fmt.Sprintf("%v", r.Name),
FullName: fmt.Sprintf("%v", r.FullName),
Data: &models.GithubRepo{
GithubId: r.ID,
Name: r.Name,
FullName: r.FullName,
HTMLUrl: r.HTMLURL,
Description: r.Description,
OwnerId: r.Owner.ID,
CloneUrl: r.CloneURL,
CreatedDate: r.CreatedAt,
UpdatedDate: r.UpdatedAt,
},
}
}

// RemoteScopes list all available scopes on the remote server
// @Summary list all available scopes on the remote server
// @Description list all available scopes on the remote server
Expand Down
228 changes: 115 additions & 113 deletions backend/plugins/github/api/remote_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,120 +137,122 @@ type repo struct {
}

type GithubAppRepo struct {
ID int `json:"id"`
NodeID string `json:"node_id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Owner struct {
Login string `json:"login"`
ID int `json:"id"`
NodeID string `json:"node_id"`
AvatarURL string `json:"avatar_url"`
GravatarID string `json:"gravatar_id"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
FollowersURL string `json:"followers_url"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
OrganizationsURL string `json:"organizations_url"`
ReposURL string `json:"repos_url"`
EventsURL string `json:"events_url"`
ReceivedEventsURL string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"owner"`
Private bool `json:"private"`
HTMLURL string `json:"html_url"`
Description string `json:"description"`
Fork bool `json:"fork"`
URL string `json:"url"`
ArchiveURL string `json:"archive_url"`
AssigneesURL string `json:"assignees_url"`
BlobsURL string `json:"blobs_url"`
BranchesURL string `json:"branches_url"`
CollaboratorsURL string `json:"collaborators_url"`
CommentsURL string `json:"comments_url"`
CommitsURL string `json:"commits_url"`
CompareURL string `json:"compare_url"`
ContentsURL string `json:"contents_url"`
ContributorsURL string `json:"contributors_url"`
DeploymentsURL string `json:"deployments_url"`
DownloadsURL string `json:"downloads_url"`
EventsURL string `json:"events_url"`
ForksURL string `json:"forks_url"`
GitCommitsURL string `json:"git_commits_url"`
GitRefsURL string `json:"git_refs_url"`
GitTagsURL string `json:"git_tags_url"`
GitURL string `json:"git_url"`
IssueCommentURL string `json:"issue_comment_url"`
IssueEventsURL string `json:"issue_events_url"`
IssuesURL string `json:"issues_url"`
KeysURL string `json:"keys_url"`
LabelsURL string `json:"labels_url"`
LanguagesURL string `json:"languages_url"`
MergesURL string `json:"merges_url"`
MilestonesURL string `json:"milestones_url"`
NotificationsURL string `json:"notifications_url"`
PullsURL string `json:"pulls_url"`
ReleasesURL string `json:"releases_url"`
SSHURL string `json:"ssh_url"`
StargazersURL string `json:"stargazers_url"`
StatusesURL string `json:"statuses_url"`
SubscribersURL string `json:"subscribers_url"`
SubscriptionURL string `json:"subscription_url"`
TagsURL string `json:"tags_url"`
TeamsURL string `json:"teams_url"`
TreesURL string `json:"trees_url"`
CloneURL string `json:"clone_url"`
MirrorURL string `json:"mirror_url"`
HooksURL string `json:"hooks_url"`
SvnURL string `json:"svn_url"`
Homepage string `json:"homepage"`
Language any `json:"language"`
ForksCount int `json:"forks_count"`
StargazersCount int `json:"stargazers_count"`
WatchersCount int `json:"watchers_count"`
Size int `json:"size"`
DefaultBranch string `json:"default_branch"`
OpenIssuesCount int `json:"open_issues_count"`
IsTemplate bool `json:"is_template"`
Topics []string `json:"topics"`
HasIssues bool `json:"has_issues"`
HasProjects bool `json:"has_projects"`
HasWiki bool `json:"has_wiki"`
HasPages bool `json:"has_pages"`
HasDownloads bool `json:"has_downloads"`
Archived bool `json:"archived"`
Disabled bool `json:"disabled"`
Visibility string `json:"visibility"`
PushedAt *time.Time `json:"pushed_at"`
CreatedAt *time.Time `json:"created_at"`
UpdatedAt *time.Time `json:"updated_at"`
AllowRebaseMerge bool `json:"allow_rebase_merge"`
TemplateRepository any `json:"template_repository"`
TempCloneToken string `json:"temp_clone_token"`
AllowSquashMerge bool `json:"allow_squash_merge"`
AllowAutoMerge bool `json:"allow_auto_merge"`
DeleteBranchOnMerge bool `json:"delete_branch_on_merge"`
AllowMergeCommit bool `json:"allow_merge_commit"`
SubscribersCount int `json:"subscribers_count"`
NetworkCount int `json:"network_count"`
License struct {
Key string `json:"key"`
Name string `json:"name"`
URL string `json:"url"`
SpdxID string `json:"spdx_id"`
NodeID string `json:"node_id"`
HTMLURL string `json:"html_url"`
} `json:"license"`
Forks int `json:"forks"`
OpenIssues int `json:"open_issues"`
Watchers int `json:"watchers"`
}

type GithubAppRepoResult struct {
TotalCount int `json:"total_count"`
Repositories []struct {
ID int `json:"id"`
NodeID string `json:"node_id"`
Name string `json:"name"`
FullName string `json:"full_name"`
Owner struct {
Login string `json:"login"`
ID int `json:"id"`
NodeID string `json:"node_id"`
AvatarURL string `json:"avatar_url"`
GravatarID string `json:"gravatar_id"`
URL string `json:"url"`
HTMLURL string `json:"html_url"`
FollowersURL string `json:"followers_url"`
FollowingURL string `json:"following_url"`
GistsURL string `json:"gists_url"`
StarredURL string `json:"starred_url"`
SubscriptionsURL string `json:"subscriptions_url"`
OrganizationsURL string `json:"organizations_url"`
ReposURL string `json:"repos_url"`
EventsURL string `json:"events_url"`
ReceivedEventsURL string `json:"received_events_url"`
Type string `json:"type"`
SiteAdmin bool `json:"site_admin"`
} `json:"owner"`
Private bool `json:"private"`
HTMLURL string `json:"html_url"`
Description string `json:"description"`
Fork bool `json:"fork"`
URL string `json:"url"`
ArchiveURL string `json:"archive_url"`
AssigneesURL string `json:"assignees_url"`
BlobsURL string `json:"blobs_url"`
BranchesURL string `json:"branches_url"`
CollaboratorsURL string `json:"collaborators_url"`
CommentsURL string `json:"comments_url"`
CommitsURL string `json:"commits_url"`
CompareURL string `json:"compare_url"`
ContentsURL string `json:"contents_url"`
ContributorsURL string `json:"contributors_url"`
DeploymentsURL string `json:"deployments_url"`
DownloadsURL string `json:"downloads_url"`
EventsURL string `json:"events_url"`
ForksURL string `json:"forks_url"`
GitCommitsURL string `json:"git_commits_url"`
GitRefsURL string `json:"git_refs_url"`
GitTagsURL string `json:"git_tags_url"`
GitURL string `json:"git_url"`
IssueCommentURL string `json:"issue_comment_url"`
IssueEventsURL string `json:"issue_events_url"`
IssuesURL string `json:"issues_url"`
KeysURL string `json:"keys_url"`
LabelsURL string `json:"labels_url"`
LanguagesURL string `json:"languages_url"`
MergesURL string `json:"merges_url"`
MilestonesURL string `json:"milestones_url"`
NotificationsURL string `json:"notifications_url"`
PullsURL string `json:"pulls_url"`
ReleasesURL string `json:"releases_url"`
SSHURL string `json:"ssh_url"`
StargazersURL string `json:"stargazers_url"`
StatusesURL string `json:"statuses_url"`
SubscribersURL string `json:"subscribers_url"`
SubscriptionURL string `json:"subscription_url"`
TagsURL string `json:"tags_url"`
TeamsURL string `json:"teams_url"`
TreesURL string `json:"trees_url"`
CloneURL string `json:"clone_url"`
MirrorURL string `json:"mirror_url"`
HooksURL string `json:"hooks_url"`
SvnURL string `json:"svn_url"`
Homepage string `json:"homepage"`
Language any `json:"language"`
ForksCount int `json:"forks_count"`
StargazersCount int `json:"stargazers_count"`
WatchersCount int `json:"watchers_count"`
Size int `json:"size"`
DefaultBranch string `json:"default_branch"`
OpenIssuesCount int `json:"open_issues_count"`
IsTemplate bool `json:"is_template"`
Topics []string `json:"topics"`
HasIssues bool `json:"has_issues"`
HasProjects bool `json:"has_projects"`
HasWiki bool `json:"has_wiki"`
HasPages bool `json:"has_pages"`
HasDownloads bool `json:"has_downloads"`
Archived bool `json:"archived"`
Disabled bool `json:"disabled"`
Visibility string `json:"visibility"`
PushedAt time.Time `json:"pushed_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
AllowRebaseMerge bool `json:"allow_rebase_merge"`
TemplateRepository any `json:"template_repository"`
TempCloneToken string `json:"temp_clone_token"`
AllowSquashMerge bool `json:"allow_squash_merge"`
AllowAutoMerge bool `json:"allow_auto_merge"`
DeleteBranchOnMerge bool `json:"delete_branch_on_merge"`
AllowMergeCommit bool `json:"allow_merge_commit"`
SubscribersCount int `json:"subscribers_count"`
NetworkCount int `json:"network_count"`
License struct {
Key string `json:"key"`
Name string `json:"name"`
URL string `json:"url"`
SpdxID string `json:"spdx_id"`
NodeID string `json:"node_id"`
HTMLURL string `json:"html_url"`
} `json:"license"`
Forks int `json:"forks"`
OpenIssues int `json:"open_issues"`
Watchers int `json:"watchers"`
} `json:"repositories"`
Repositories []GithubAppRepo `json:"repositories"`
}

type GithubRemotePagination struct {
Expand Down
Loading