Skip to content

[teams] use owner's GitLab account by default #5900

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 1 commit into from
Oct 1, 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
9 changes: 7 additions & 2 deletions components/dashboard/src/projects/NewProject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,13 @@ export default function NewProject() {
if (reposInAccounts.length === 0) {
setSelectedAccount(undefined);
} else {
const mostRecent = reposInAccounts.reduce((prev, current) => (prev.installationUpdatedAt || 0) > (current.installationUpdatedAt || 0) ? prev : current);
setSelectedAccount(mostRecent.account);
const first = reposInAccounts[0];
if (!!first.installationUpdatedAt) {
const mostRecent = reposInAccounts.reduce((prev, current) => (prev.installationUpdatedAt || 0) > (current.installationUpdatedAt || 0) ? prev : current);
setSelectedAccount(mostRecent.account);
} else {
setSelectedAccount(first.account);
}
}

}, [reposInAccounts]);
Expand Down
14 changes: 12 additions & 2 deletions components/server/ee/src/gitlab/gitlab-app-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ export class GitLabAppSupport {
const api = new Gitlab({ oauthToken });

const result: ProviderRepository[] = [];
const ownersRepos: ProviderRepository[] = [];

const identity = params.user.identities.find(i => i.authProviderId === "Public-GitLab");
if (!identity) {
return result;
}
const usersGitLabAccount = identity.authName;

// cf. https://docs.gitlab.com/ee/api/projects.html#list-all-projects
// we are listing only those projects with access level of maintainers.
Expand All @@ -34,17 +41,20 @@ export class GitLabAppSupport {
const cloneUrl = anyProject.http_url_to_repo as string;
const updatedAt = anyProject.last_activity_at as string;
const accountAvatarUrl = anyProject.owner?.avatar_url as string;
const account = fullPath.split("/")[0];

result.push({
(account === usersGitLabAccount ? ownersRepos : result).push({
name: project.name,
account: fullPath.split("/")[0],
account,
cloneUrl,
updatedAt,
accountAvatarUrl,
// inUse: // todo(at) compute usage via ProjectHooks API
})
}

// put owner's repos first. the frontend will pick first account to continue with
result.unshift(...ownersRepos);
return result;
}

Expand Down