Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • jw_sonar
  • jw_sonar_backup
  • main
  • move-to-esm-only
  • open_tool_for_self_hosting
  • v5.0
  • v4.1
  • v4.2
8 results

Target

Select target project
  • dojo_project/projects/shared/nodesharedcode
1 result
Select Git revision
  • jw_sonar
  • jw_sonar_backup
  • main
  • move-to-esm-only
  • open_tool_for_self_hosting
  • v5.0
  • v4.1
  • v4.2
8 results
Show changes
Commits on Source (6)
......@@ -3,11 +3,19 @@ class SharedConfig {
public readonly logsFolder: string;
public gitlab: {
apiURL: string
};
constructor() {
this.production = process.env.NODE_ENV === 'production';
this.logsFolder = process.env.LOGS_FOLDER || '';
this.gitlab = {
apiURL: process.env.GITLAB_API_URL || ''
};
}
}
......
......@@ -2,6 +2,10 @@ import Ajv, { ErrorObject, JTDSchemaType } from 'ajv/dist/jtd';
import fs from 'fs';
import JSON5 from 'json5';
import AssignmentFile from '../../types/Dojo/AssignmentFile';
import GitlabPipelineStatus from '../../types/Gitlab/GitlabPipelineStatus';
import DojoStatusCode from '../../types/Dojo/DojoStatusCode';
import GitlabPipeline from '../../types/Gitlab/GitlabPipeline';
import SharedGitlabManager from '../../managers/SharedGitlabManager';
class SharedAssignmentHelper {
......@@ -69,6 +73,37 @@ class SharedAssignmentHelper {
};
}
}
async isPublishable(repositoryId: number): Promise<{ isPublishable: boolean, lastPipeline: GitlabPipeline | null, status?: { code: DojoStatusCode, message: string } }> {
const pipelines = await SharedGitlabManager.getRepositoryPipelines(repositoryId, 'main');
if ( pipelines.length > 0 ) {
const lastPipeline = pipelines[0];
if ( lastPipeline.status != GitlabPipelineStatus.SUCCESS ) {
return {
isPublishable: false,
lastPipeline : pipelines[0],
status : {
code : DojoStatusCode.ASSIGNMENT_PUBLISH_PIPELINE_FAILED,
message: 'Last pipeline status is not "success".'
}
};
} else {
return {
isPublishable: true,
lastPipeline : pipelines[0]
};
}
} else {
return {
isPublishable: false,
lastPipeline : null,
status : {
code : DojoStatusCode.ASSIGNMENT_PUBLISH_NO_PIPELINE,
message: 'No pipeline found for this assignment.'
}
};
}
}
}
......
import axios from 'axios';
import GitlabPipeline from '../types/Gitlab/GitlabPipeline';
import GitlabRoute from '../types/Gitlab/GitlabRoute';
import SharedConfig from '../config/SharedConfig';
class GitlabManager {
private getApiUrl(route: GitlabRoute): string {
return `${ SharedConfig.gitlab.apiURL }${ route }`;
}
async getRepositoryPipelines(repoId: number, branch: string = 'main'): Promise<Array<GitlabPipeline>> {
const response = await axios.get<Array<GitlabPipeline>>(this.getApiUrl(GitlabRoute.REPOSITORY_PIPELINES).replace('{{id}}', String(repoId)), {
params: {
ref: branch
}
});
return response.data;
}
}
export default new GitlabManager();
enum DojoStatusCode {
CLIENT_NOT_SUPPORTED = 100,
CLIENT_VERSION_NOT_SUPPORTED = 110
CLIENT_VERSION_NOT_SUPPORTED = 110,
ASSIGNMENT_PUBLISH_NO_PIPELINE = 200,
ASSIGNMENT_PUBLISH_PIPELINE_FAILED = 201
}
......
import GitlabPipelineStatus from './GitlabPipelineStatus';
import GitlabPipelineSource from './GitlabPipelineSource';
import GitlabUser from './GitlabUser';
interface GitlabPipeline {
id: number,
iid: number,
project_id: number,
status: GitlabPipelineStatus,
source: GitlabPipelineSource,
ref: string,
sha: string,
before_sha: string,
tag: boolean,
name: string,
yaml_errors: string | null,
user: GitlabUser,
web_url: string,
created_at: string,
updated_at: string,
started_at: string | null,
finished_at: string | null,
committed_at: string | null,
duration: number | null,
queued_duration: number | null,
coverage: string | null,
}
export default GitlabPipeline;
\ No newline at end of file
enum GitlabPipelineSource {
PUSH = 'push',
WEB = 'web',
TRIGGER = 'trigger',
SCHEDULE = 'schedule',
API = 'api',
EXTERNAL = 'external',
PIPELINE = 'pipeline',
CHAT = 'chat',
WEBIDE = 'webide',
MERGE_REQUEST = 'merge_request_event',
EXTERNAL_PULL_REQUEST = 'external_pull_request_event',
PARENT_PIPELINE = 'parent_pipeline',
ON_DEMAND_DAST_SCAN = 'ondemand_dast_scan',
ON_DEMAND_DAST_VALIDATION = 'ondemand_dast_validation',
}
export default GitlabPipelineSource;
enum GitlabPipelineStatus {
CREATED = 'created',
WAITING_FOR_RESOURCE = 'waiting_for_resource',
PREPARING = 'preparing',
PENDING = 'pending',
RUNNING = 'running',
SUCCESS = 'success',
FAILED = 'failed',
CANCELED = 'canceled',
SKIPPED = 'skipped',
MANUAL = 'manual',
SCHEDULED = 'scheduled'
}
export default GitlabPipelineStatus;
......@@ -12,6 +12,7 @@ enum GitlabRoute {
REPOSITORY_BRANCHES_PROTECT = '/projects/{{id}}/protected_branches',
REPOSITORY_TREE = '/projects/{{id}}/repository/tree',
REPOSITORY_FILE = '/projects/{{id}}/repository/files/{{filePath}}',
REPOSITORY_PIPELINES = '/projects/{{id}}/pipelines',
}
......