fix(events,github): use correct repo URL
`$.repository.url` was used, but contained values of pattern `https://api.github.com/repos/{org}/{repo}` for `repository` events and `https://github.com/{org}/{repo}` for `push` events. Fixes: #25951 Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
@@ -4,4 +4,5 @@
|
||||
|
||||
Fix GitHub `repository` event support.
|
||||
|
||||
`$.repository.organization` is only provided for `push` events. Switched to `$.organization.login` instead.
|
||||
- `$.repository.organization` is only provided for `push` events. Switched to `$.organization.login` instead.
|
||||
- `$.repository.url` is not always returning the expected and required value. Use `$.repository.html_url` instead.
|
||||
|
||||
@@ -665,7 +665,7 @@ describe('GithubEntityProvider', () => {
|
||||
event: EventParams<PushEvent | RepositoryEvent>,
|
||||
options?: { branch?: string; catalogFilePath?: string },
|
||||
): DeferredEntity[] => {
|
||||
const url = `${event.eventPayload.repository.url}/blob/${
|
||||
const url = `${event.eventPayload.repository.html_url}/blob/${
|
||||
options?.branch ?? 'main'
|
||||
}/${options?.catalogFilePath ?? 'catalog-info.yaml'}`;
|
||||
return createExpectedEntitiesForUrl(url);
|
||||
@@ -687,6 +687,7 @@ describe('GithubEntityProvider', () => {
|
||||
name: 'test-repo',
|
||||
organization,
|
||||
topics: [],
|
||||
html_url: `https://github.com/${organization}/test-repo`,
|
||||
url: `https://github.com/${organization}/test-repo`,
|
||||
} as Partial<PushEvent['repository']>;
|
||||
|
||||
@@ -963,7 +964,8 @@ describe('GithubEntityProvider', () => {
|
||||
): EventParams<RepositoryEvent> => {
|
||||
const repo = {
|
||||
name: 'test-repo',
|
||||
url: 'https://github.com/test-org/test-repo',
|
||||
html_url: 'https://github.com/test-org/test-repo',
|
||||
url: 'https://api.github.com/repos/test-org/test-repo',
|
||||
default_branch: 'main',
|
||||
master_branch: 'main',
|
||||
topics: [],
|
||||
|
||||
@@ -331,7 +331,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
}
|
||||
|
||||
const repoName = event.repository.name;
|
||||
const repoUrl = event.repository.url;
|
||||
const repoUrl = event.repository.html_url;
|
||||
this.logger.debug(`handle github:push event for ${repoName} - ${repoUrl}`);
|
||||
|
||||
const branch =
|
||||
@@ -356,13 +356,13 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
// so we will process the change based in this data
|
||||
// https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push
|
||||
const added = this.collectDeferredEntitiesFromCommit(
|
||||
event.repository.url,
|
||||
repoUrl,
|
||||
branch,
|
||||
event.commits,
|
||||
(commit: Commit) => [...commit.added],
|
||||
);
|
||||
const removed = this.collectDeferredEntitiesFromCommit(
|
||||
event.repository.url,
|
||||
repoUrl,
|
||||
branch,
|
||||
event.commits,
|
||||
(commit: Commit) => [...commit.removed],
|
||||
@@ -381,14 +381,12 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
keys: [
|
||||
...new Set([
|
||||
...modified.map(
|
||||
filePath =>
|
||||
`url:${event.repository.url}/tree/${branch}/${filePath}`,
|
||||
filePath => `url:${repoUrl}/tree/${branch}/${filePath}`,
|
||||
),
|
||||
...modified.map(
|
||||
filePath =>
|
||||
`url:${event.repository.url}/blob/${branch}/${filePath}`,
|
||||
filePath => `url:${repoUrl}/blob/${branch}/${filePath}`,
|
||||
),
|
||||
`url:${event.repository.url}/tree/${branch}/${catalogPath}`,
|
||||
`url:${repoUrl}/tree/${branch}/${catalogPath}`,
|
||||
]),
|
||||
],
|
||||
});
|
||||
@@ -527,7 +525,7 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
private async onRepoRenamed(event: RepositoryRenamedEvent) {
|
||||
const repository = this.createRepoFromEvent(event);
|
||||
const oldRepoName = event.changes.repository.name.from;
|
||||
const urlParts = event.repository.url.split('/');
|
||||
const urlParts = repository.url.split('/');
|
||||
urlParts[urlParts.length - 1] = oldRepoName;
|
||||
const oldRepoUrl = urlParts.join('/');
|
||||
const oldRepository: Repository = {
|
||||
@@ -632,7 +630,10 @@ export class GithubEntityProvider implements EntityProvider, EventSubscriber {
|
||||
|
||||
private createRepoFromEvent(event: RepositoryEvent | PushEvent): Repository {
|
||||
return {
|
||||
url: event.repository.url,
|
||||
// $.repository.url can be a value like
|
||||
// "https://api.github.com/repos/{org}/{repo}"
|
||||
// or "https://github.com/{org}/{repo}"
|
||||
url: event.repository.html_url,
|
||||
name: event.repository.name,
|
||||
defaultBranchRef: event.repository.default_branch,
|
||||
repositoryTopics: event.repository.topics,
|
||||
|
||||
Reference in New Issue
Block a user