Skip to content

Commit

Permalink
Merge pull request #126 from vbihun/handle-error-in-data-provider-and…
Browse files Browse the repository at this point in the history
…-config-validator

Handle errors in dataProvider and configValidator
  • Loading branch information
vbihun authored Sep 26, 2024
2 parents d27d338 + 9f6fe2b commit 93cbc3c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
15 changes: 11 additions & 4 deletions src/entry/config-validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ import { ConfigValidatorResult, ConfigValidatorResponse } from '@atlassian/forge
import { getConnectedGroups } from '../../services/group';

export const configValidator = async (): Promise<ConfigValidatorResult> => {
const connectedGroups = await getConnectedGroups();
const appConfigured = connectedGroups && connectedGroups.length > 0;
try {
const connectedGroups = await getConnectedGroups();
const appConfigured = connectedGroups && connectedGroups.length > 0;

const response = new ConfigValidatorResponse(appConfigured);
return response.build();
const response = new ConfigValidatorResponse(appConfigured);
return response.build();
} catch (e) {
console.error('Could not determine installation state when invoking config validator');
const response = new ConfigValidatorResponse(false);
response.error = 'Could not determine installation state';
return response.build();
}
};
27 changes: 22 additions & 5 deletions src/entry/data-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@ import { GitlabHttpMethodError } from '../../models/errors';
export const dataProvider = async (
request: DataProviderPayload,
): Promise<DataProviderResult | ForgeInvocationError> => {
const {
project: { id: projectId, default_branch: defaultBranch, name: projectName },
groupToken,
} = await getProjectDataFromUrl(request.url);
let projectId: number;
let defaultBranch: string;
let projectName: string;
let groupToken: string;
let trackingBranch: string;

try {
({
project: { id: projectId, default_branch: defaultBranch, name: projectName },
groupToken,
} = await getProjectDataFromUrl(request.url));
} catch (e) {
console.error(`Error while getting project data from URL in dataProvider ${e}`);
return null;
}

if (!projectId) {
console.warn('Cannot get GitLab project data by provided link.');
return null;
}

const trackingBranch = await getTrackingBranchName(groupToken, projectId, defaultBranch);
try {
trackingBranch = await getTrackingBranchName(groupToken, projectId, defaultBranch);
} catch (e) {
console.error(`Error while getting tracking branch name in dataProvider ${e}`);

return null;
}

const backfillData: BackfillData = {
builds: [],
Expand Down

0 comments on commit 93cbc3c

Please sign in to comment.