Skip to content

Commit 45ce2c8

Browse files
committed
Add support to filter out archived GitLab projects
1 parent 861a964 commit 45ce2c8

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ Go to [Settings / Access Tokens](https://gitlab.com/-/profile/personal_access_to
5656

5757
Leave it null for the first run of the script. Then the script will show you which projects there are. Can be either string or number.
5858

59+
#### gitlab.listArchivedProjects
60+
61+
When listing projects on the first run (projectID = null), include archived ones too. The default is *true*.
62+
5963
#### gitlab.sessionCookie
6064

6165
GitLab's API [does not allow downloading of attachments](https://gitlab.com/gitlab-org/gitlab/-/issues/24155) and only images can be downloaded using HTTP. To work around this limitation and enable binary attachments to be migrated one can use the session cookie set in the browser after logging in to the gitlab instance. The cookie is named `_gitlab_session`.

sample_settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default {
55
// url: 'https://gitlab.mycompany.com',
66
token: '{{gitlab private token}}',
77
projectId: null,
8+
listArchivedProjects: true,
89
sessionCookie: null,
910
},
1011
github: {

src/gitlabHelper.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class GitlabHelper {
2323
gitlabUrl?: string;
2424
gitlabToken: string;
2525
gitlabProjectId: number;
26+
archived?: boolean;
2627
sessionCookie: string;
2728

2829
host: string;
@@ -41,6 +42,7 @@ export class GitlabHelper {
4142
this.host = this.host.endsWith('/')
4243
? this.host.substring(0, this.host.length - 1)
4344
: this.host;
45+
this.archived = gitlabSettings.listArchivedProjects ?? true;
4446
this.sessionCookie = gitlabSettings.sessionCookie;
4547
this.allBranches = null;
4648
}
@@ -50,7 +52,12 @@ export class GitlabHelper {
5052
*/
5153
async listProjects() {
5254
try {
53-
const projects = await this.gitlabApi.Projects.all({ membership: true });
55+
let projects;
56+
if (this.archived) {
57+
projects = await this.gitlabApi.Projects.all({ membership: true });
58+
} else {
59+
projects = await this.gitlabApi.Projects.all({ membership: true, archived: this.archived });
60+
}
5461

5562
// print each project with info
5663
for (let project of projects) {

src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export interface GitlabSettings {
5151
url?: string;
5252
token: string;
5353
projectId: number;
54+
listArchivedProjects?: boolean;
5455
sessionCookie: string;
5556
}
5657

0 commit comments

Comments
 (0)