Skip to content

Commit

Permalink
removing ugc from logging, and adding logging to client calls
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickAtlassian committed Sep 8, 2023
1 parent 1c2da7c commit ea1fbe8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
38 changes: 23 additions & 15 deletions src/client/gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const callGitlab = async (

if (resp.status >= 300) {
const msg = isTextBody(config) ? await resp.text() : JSON.stringify(await resp.json());
console.warn(`Gitlab client received a status code of ${resp.status} while fetching ${path}. Error: ${msg}`);
console.warn(`Gitlab client received a status code of ${resp.status} while making the request. Error: ${msg}`);
throw new GitlabHttpMethodError(resp.status, resp.statusText);
}

Expand All @@ -107,13 +107,15 @@ export const getGroupsData = async (

const queryParams = queryParamsGenerator(params);

console.log(`Calling gitlab to get groups. Query params: ${queryParams}`);
const { data } = await callGitlab(`/api/v4/groups?${queryParams}`, groupAccessToken);

return data;
};

export const registerGroupWebhook = async (payload: RegisterWebhookPayload): Promise<number> => {
const { groupId, token: groupToken, url, signature } = payload;
console.log(`Calling gitlab to register webhook`);
const {
data: { id },
} = await callGitlab(
Expand All @@ -135,6 +137,7 @@ export const registerGroupWebhook = async (payload: RegisterWebhookPayload): Pro

export const deleteGroupWebhook = async (groupId: number, hookId: number, groupToken: string): Promise<void> => {
try {
console.log(`Calling gitlab to delete webhook`);
await callGitlab(`/api/v4/groups/${groupId}/hooks/${hookId}`, groupToken, { method: HttpMethod.DELETE });
} catch (e) {
if (e.statusText.includes('Not Found')) {
Expand All @@ -150,6 +153,7 @@ export const getGroupWebhook = async (
groupToken: string,
): Promise<{ id: number } | null> => {
try {
console.log(`Calling gitlab to get webhook`);
const { data: webhook } = await callGitlab(`/api/v4/groups/${groupId}/hooks/${hookId}`, groupToken);

return webhook;
Expand All @@ -162,12 +166,14 @@ export const getGroupWebhook = async (
};

export const getGroupAccessTokens = async (groupToken: string, groupId: number): Promise<GroupAccessToken[]> => {
console.log(`Calling gitlab to get group access tokens`);
const { data: groupAccessTokenList } = await callGitlab(`/api/v4/groups/${groupId}/access_tokens`, groupToken);

return groupAccessTokenList;
};

export const getCommitDiff = async (groupToken: string, projectId: number, sha: string): Promise<CommitFileDiff[]> => {
console.log(`Calling gitlab to get commit diff`);
const { data: diff } = await callGitlab(`/api/v4/projects/${projectId}/repository/commits/${sha}/diff`, groupToken);

return diff;
Expand All @@ -184,7 +190,7 @@ export const getFileContent = async (
};

const queryParams = queryParamsGenerator(params);

console.log(`Calling gitlab to get file content`);
const fileRaw = await callGitlab(
`/api/v4/projects/${projectId}/repository/files/${encodeURIComponent(filePath)}/raw?${queryParams}`,
groupToken,
Expand Down Expand Up @@ -214,30 +220,21 @@ export const getProjects = async (
};

const queryParams = queryParamsGenerator(params);
console.log(`Calling gitlab to get projects`);
const { data, headers } = await callGitlab(`/api/v4/groups/${groupId}/projects?${queryParams}`, groupToken);

return { data, headers };
};

export const getProjectById = async (groupToken: string, projectId: number): Promise<GitlabAPIProject> => {
console.log(`Calling gitlab to get project by id`);
const { data: project } = await callGitlab(`/api/v4/projects/${projectId}`, groupToken);

return project;
};

export const searchFileByPath = async (groupToken: string, projectId: number, path: string, branch: string) => {
const params = {
ref: branch,
};

const queryParams = queryParamsGenerator(params);

const file = await callGitlab(`/api/v4/projects/${projectId}/repository/files/${path}?${queryParams}`, groupToken);

return file;
};

export const getProjectLanguages = async (groupToken: string, projectId: number) => {
console.log(`Calling gitlab to get project languages`);
const { data: languages } = await callGitlab(`/api/v4/projects/${projectId}/languages`, groupToken);

return languages;
Expand All @@ -248,6 +245,9 @@ export const getProjectVariable = async (
projectId: number,
variable: string,
): Promise<string | null | never> => {
console.log(
`Calling gitlab to get project variable ${variable}. It is normal for the request to 404 if the variable does not exist.`,
);
const {
data: { value },
} = await callGitlab(`/api/v4/projects/${projectId}/variables/${variable}`, groupToken);
Expand All @@ -259,6 +259,7 @@ export const getProjectBranch = async (
projectId: number,
branchName: string,
): Promise<ProjectBranch> => {
console.log(`Calling gitlab to get project branch`);
const { data: branch } = await callGitlab(
`/api/v4/projects/${projectId}/repository/branches/${branchName}`,
groupToken,
Expand All @@ -276,7 +277,7 @@ export const getOwnedProjectsBySearchCriteria = async (
};

const queryParams = queryParamsGenerator(params);

console.log(`Calling gitlab to get owned projects by search criteria`);
const { data } = await callGitlab(`/api/v4/projects?${queryParams}`, groupToken);

return data;
Expand Down Expand Up @@ -304,6 +305,7 @@ export const getProjectRecentDeployments: GitlabPaginatedFetch<
const queryParams = queryParamsGenerator(params);
const path = `/api/v4/projects/${projectId}/deployments?${queryParams}`;

console.log(`Calling gitlab to get project recent deployments`);
const { data, headers } = await callGitlab(path, groupToken);

return { data, headers };
Expand Down Expand Up @@ -341,18 +343,21 @@ export const getMergeRequests: GitlabPaginatedFetch<
const queryParams = queryParamsGenerator(params);
const path = `/api/v4/projects/${projectId}/merge_requests?${queryParams}`;

console.log(`Calling gitlab to get merge requests`);
const { data, headers } = await callGitlab(path, groupToken);

return { data, headers };
};

export const getProjectDeploymentById = async (projectId: number, deploymentId: number, groupToken: string) => {
console.log(`Calling gitlab to get project deployment by id`);
const { data } = await callGitlab(`/api/v4/projects/${projectId}/deployments/${deploymentId}`, groupToken);

return data;
};

export const getEnvironments = async (projectId: number, groupToken: string): Promise<Environment[]> => {
console.log(`Calling gitlab to get environments`);
const { data } = await callGitlab(`/api/v4/projects/${projectId}/environments`, groupToken);

return data;
Expand All @@ -379,6 +384,7 @@ export const getProjectRecentPipelines: GitlabPaginatedFetch<
const queryParams = queryParamsGenerator(params);
const path = `/api/v4/projects/${projectId}/pipelines?${queryParams}`;

console.log(`Calling gitlab to get project recent pipelines`);
const { data, headers } = await callGitlab(path, groupToken);
return { data, headers };
};
Expand All @@ -395,6 +401,7 @@ export const createFileInProject = async (
) => {
const path = `/api/v4/projects/${projectId}/repository/files/${filePath}`;

console.log(`Calling gitlab to create file in project`);
const { data } = await callGitlab(
path,
groupToken,
Expand Down Expand Up @@ -422,6 +429,7 @@ export const createMergeRequest = async (
) => {
const path = `/api/v4/projects/${projectId}/merge_requests`;

console.log(`Calling gitlab to create merge request`);
const { data } = await callGitlab(
path,
groupToken,
Expand Down
3 changes: 1 addition & 2 deletions src/entry/data-provider/callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import { CallbackPayload } from './types';
import { serverResponse } from '../../utils/webtrigger-utils';

export const callback = (input: CallbackPayload) => {
const { success, url, errorMessage } = input;
const { success, errorMessage } = input;

if (!success) {
console.error({
message: 'Error processing dataProvider module',
url,
errorMessage,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export const handlePipelineEvent = async (event: PipelineEvent, groupToken: stri

if (!isEventForTrackingBranch(event, trackingBranch)) {
console.log({
message: 'Received push event for non-tracking branch',
ref,
trackingBranch,
message: 'Received push event for non-tracking branch. Ignoring event',
});
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ export const handlePushEvent = async (event: PushEvent, groupToken: string, clou

if (!isEventForTrackingBranch(event, trackingBranch)) {
console.log({
message: 'Received push event for non-tracking branch',
ref: event.ref,
trackingBranch,
message: 'Received push event for non-tracking branch. Ignoring event',
});
return;
}

console.log('Received push event for tracking branch -', trackingBranch);
console.log('Received push event for tracking branch. Processing event');

const { componentsToCreate, componentsToUpdate, componentsToUnlink } = await findConfigAsCodeFileChanges(
event,
Expand Down
4 changes: 2 additions & 2 deletions src/import-queue-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resolver.define('import', async (req) => {
try {
if (!hasComponent) {
const component = await backOff(() => createComponent(cloudId, project), backOffConfig);
console.log(`GitLab project ${name}:${id} was imported. Compass component was created - ${component.id}.`);
console.log(`GitLab project ${id} was imported. Compass component was created - ${component.id}.`);

if (shouldOpenMR) {
await createMRWithCompassYML(project, component.id, groupId);
Expand Down Expand Up @@ -90,7 +90,7 @@ resolver.define('import', async (req) => {
}
}
} catch (err) {
console.error(`Failed to create or update compass component for "${name}" project after all retries`, err);
console.error(`Failed to create or update compass component for project "${id}" after all retries`, err);

await setFailedRepositoriesToStore(project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ const newGetDeploymentsForEnvironments = async (
.filter((event) => event !== null);
const unprocessedEvents = recentDeployments.length - dataProviderDeploymentEvents.length;
if (unprocessedEvents > 0) {
console.log(`unprocessed deployment events count: ${unprocessedEvents} for environment ${projectEnv}`);
console.log(
`unprocessed deployment events count: ${unprocessedEvents} for environment id ${projectEnv.id} tier ${projectEnv.tier}`,
);
}
return dataProviderDeploymentEvents;
});
Expand Down

0 comments on commit ea1fbe8

Please sign in to comment.