Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay-gupta7 committed Jan 16, 2025
1 parent 38d5480 commit e7dcc35
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,16 +238,16 @@ export class GitlabTokenStorage extends GitTokenStorage {
};
} catch (err) {
console.error(err);
return [];
}
return [];
}

public async writeChangeset(changeset: Record<string, string>, message: string, branch: string, shouldCreateBranch?: boolean): Promise<boolean> {
if (!this.projectId) throw new Error('Missing Project ID');

const branches = await this.fetchBranches();
const rootPath = this.path.endsWith('.json') ? this.path.split('/').slice(0, -1).join('/') : this.path;
const gitkeepPath = `${this.path}/.gitkeep`;
const pathToCreate = this.path.endsWith('.json') ? this.path : `${this.path}/.gitkeep`;

if (shouldCreateBranch && !branches.includes(branch)) {
const sourceBranch = this.previousSourceBranch || this.source;
Expand All @@ -256,11 +256,11 @@ export class GitlabTokenStorage extends GitTokenStorage {

// Directories cannot be created empty (Source: https://gitlab.com/gitlab-org/gitlab/-/issues/247503)
try {
await this.gitlabClient.RepositoryFiles.show(this.projectId, gitkeepPath, branch);
await this.gitlabClient.RepositoryFiles.show(this.projectId, pathToCreate, branch);
} catch {
await this.gitlabClient.RepositoryFiles.create(
this.projectId,
gitkeepPath,
pathToCreate,
branch,
'{}',
message,
Expand Down Expand Up @@ -292,7 +292,9 @@ export class GitlabTokenStorage extends GitTokenStorage {
throw new Error(e);
}

await this.cleanupGitkeepFiles(rootPath, branch, message);
if (!this.path.endsWith('.json')) {
await this.cleanupGitkeepFiles(rootPath, branch, message);
}
return true;
}

Expand Down

0 comments on commit e7dcc35

Please sign in to comment.