Skip to content

Commit c44c8ac

Browse files
committed
v4
1 parent 77fdcc8 commit c44c8ac

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

components/server/src/github/github-context-parser.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ class TestGithubContextParser {
320320
})
321321
}
322322

323-
324323
@test public async testCommitContext_02_notExistingCommit() {
325324
try {
326325
await this.parser.handle({}, this.user, 'https://github.com/gitpod-io/gitpod-test-repo/commit/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
@@ -537,5 +536,13 @@ class TestGithubContextParser {
537536
)
538537
}
539538

539+
@test public async testFetchCommitHistory() {
540+
const result = await this.parser.fetchCommitHistory({}, this.user, 'https://github.com/gitpod-io/gitpod-test-repo', '409ac2de49a53d679989d438735f78204f441634');
541+
expect(result).to.deep.equal([
542+
'506e5aed317f28023994ecf8ca6ed91430e9c1a4',
543+
'f5b041513bfab914b5fbf7ae55788d9835004d76',
544+
])
545+
}
546+
540547
}
541548
module.exports = new TestGithubContextParser() // Only to circumvent no usage warning :-/

components/server/src/github/github-context-parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
420420
public async fetchCommitHistory(ctx: TraceContext, user: User, contextUrl: string, sha: string): Promise<string[]> {
421421
const span = TraceContext.startSpan("GithubContextParser.fetchCommitHistory", ctx);
422422
const maxDepth = 100;
423-
const maxAgeMs = 1000 * 3600 * 24 * 10;
423+
// const maxAgeMs = 1000 * 3600 * 24 * 10;
424424

425425
try {
426426
if (sha.length != 40) {
@@ -439,7 +439,7 @@ export class GithubContextParser extends AbstractContextParser implements IConte
439439
repository(name: "${repoName}", owner: "${owner}") {
440440
object(oid: "${sha}") {
441441
... on Commit {
442-
history(first: ${maxDepth}, since: "${new Date(Date.now() - maxAgeMs).toISOString()}") {
442+
history(first: ${maxDepth}` + /* , since: "${new Date(Date.now() - maxAgeMs).toISOString()}" */ `) {
443443
edges {
444444
node {
445445
oid

components/server/src/gitlab/gitlab-context-parser.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,14 @@ class TestGitlabContextParser {
547547
})
548548
}
549549

550+
@test public async testFetchCommitHistory() {
551+
const result = await this.parser.fetchCommitHistory({}, this.user, 'https://gitlab.com/AlexTugarev/gp-test', '80948e8cc8f0e851e89a10bc7c2ee234d1a5fbe7');
552+
expect(result).to.deep.equal([
553+
'4447fbc4d46e6fd1ee41fb1b992702521ae078eb',
554+
'f2d9790f2752a794517b949c65a773eb864844cd',
555+
])
556+
}
557+
550558
}
551559

552560
module.exports = new TestGitlabContextParser();

components/server/src/gitlab/gitlab-context-parser.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,26 @@ export class GitlabContextParser extends AbstractContextParser implements IConte
340340
};
341341
}
342342

343-
public async fetchCommitHistory(ctx: TraceContext, user: User, contextUrl: string, commit: string): Promise<string[]> {
344-
// FIXME
345-
return [];
343+
public async fetchCommitHistory(ctx: TraceContext, user: User, contextUrl: string, sha: string): Promise<string[]> {
344+
const maxDepth = 100;
345+
// const maxAgeMs = 1000 * 3600 * 24 * 100;
346+
347+
const { owner, repoName } = await this.parseURL(user, contextUrl);
348+
const projectId = `${owner}/${repoName}`;
349+
const result = await this.gitlabApi.run<GitLab.Commit[]>(user, async g => {
350+
return g.Commits.all(projectId, {
351+
ref_name: sha,
352+
// since: new Date(Date.now() - maxAgeMs).toISOString(),
353+
per_page: maxDepth,
354+
page: 1,
355+
});
356+
});
357+
if (GitLab.ApiError.is(result)) {
358+
if (result.message === 'GitLab responded with code 404') {
359+
throw new Error(`Couldn't find commit #${sha} in repository ${projectId}.`);
360+
}
361+
throw result;
362+
}
363+
return result.slice(1).map((c: GitLab.Commit) => c.id);
346364
}
347365
}

0 commit comments

Comments
 (0)