Skip to content

Commit

Permalink
Merge pull request #2178 from marioneyraud/front-github-actions-button
Browse files Browse the repository at this point in the history
Front add Gihub actions button
  • Loading branch information
pascalgrimaud authored Jun 20, 2022
2 parents 778c601 + c54b9ab commit 9aed517
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/main/webapp/app/common/domain/Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export enum Service {
FLYWAY = 'FLYWAY',
FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS = 'FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS',
FRONTEND_MAVEN_PLUGIN = 'FRONTEND_MAVEN_PLUGIN',
GITHUB_ACTIONS = 'GITHUB_ACTIONS',
INITIALIZATION = 'INITIALIZATION',
JACOCO_CHECK_MINIMAL_COVERAGE = 'JACOCO_CHECK_MINIMAL_COVERAGE',
JAVA_BASE = 'JAVA_BASE',
Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/common/secondary/RestServiceId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const SERVICES: Record<string, Service> = {
flyway: Service.FLYWAY,
'flyway-user-and-authority-changelogs': Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS,
'frontend-maven-plugin': Service.FRONTEND_MAVEN_PLUGIN,
'github-actions': Service.GITHUB_ACTIONS,
init: Service.INITIALIZATION,
jib: Service.JIB,
'jacoco-check-min-coverage': Service.JACOCO_CHECK_MINIMAL_COVERAGE,
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'bootstrap';
import '../content/css/custom.css';
import { MittAlertListener } from '@/common/secondary/alert/MittAlertListener';
import { RestModulesRepository } from './module/secondary/RestModulesRepository';
import SetupRepository from '@/springboot/secondary/SetupRepository';

const app = createApp(App);
const pinia = createPinia();
Expand All @@ -44,6 +45,7 @@ const projectRepository = new ProjectRepository(axiosHttp, projectHistoryReposit
const angularRepository = new AngularRepository(axiosHttp, projectHistoryRepository);
const reactRepository = new ReactRepository(axiosHttp, projectHistoryRepository);
const springBootRepository = new SpringBootRepository(axiosHttp, projectHistoryRepository);
const setupRepository = new SetupRepository(axiosHttp, projectHistoryRepository);
const svelteRepository = new SvelteRepository(axiosHttp, projectHistoryRepository);
const vueRepository = new VueRepository(axiosHttp, projectHistoryRepository);
const modulesRepository = new RestModulesRepository(axiosHttp);
Expand All @@ -60,6 +62,7 @@ app.provide('projectService', projectRepository);
app.provide('projectHistoryService', projectHistoryRepository);
app.provide('reactService', reactRepository);
app.provide('springBootService', springBootRepository);
app.provide('setupService', setupRepository);
app.provide('vueService', vueRepository);
app.provide('svelteService', svelteRepository);
app.provide('modules', modulesRepository);
Expand Down
6 changes: 5 additions & 1 deletion src/main/webapp/app/springboot/domain/SetupService.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export interface SetupService {}
import { Project } from '@/springboot/domain/Project';

export interface SetupService {
addGithubActions(project: Project): Promise<void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ServiceProjection =
| 'flyway'
| 'flyway-with-users-and-authority-changelogs'
| 'frontend-maven-plugin'
| 'github-actions'
| 'jacoco-check-minimal-coverage'
| 'java-base'
| 'jib'
Expand Down Expand Up @@ -74,6 +75,7 @@ const SERVICES_PROJECTION: Record<Service, ServiceProjection> = {
[Service.FLYWAY]: 'flyway',
[Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS]: 'flyway-with-users-and-authority-changelogs',
[Service.FRONTEND_MAVEN_PLUGIN]: 'frontend-maven-plugin',
[Service.GITHUB_ACTIONS]: 'github-actions',
[Service.INITIALIZATION]: 'initialization',
[Service.JACOCO_CHECK_MINIMAL_COVERAGE]: 'jacoco-check-minimal-coverage',
[Service.JAVA_BASE]: 'java-base',
Expand Down Expand Up @@ -135,6 +137,7 @@ const SERVICES: Record<ServiceProjection, Service> = {
flyway: Service.FLYWAY,
'flyway-with-users-and-authority-changelogs': Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS,
'frontend-maven-plugin': Service.FRONTEND_MAVEN_PLUGIN,
'github-actions': Service.GITHUB_ACTIONS,
initialization: Service.INITIALIZATION,
'jacoco-check-minimal-coverage': Service.JACOCO_CHECK_MINIMAL_COVERAGE,
'java-base': Service.JAVA_BASE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { defineComponent } from 'vue';
import { defineComponent, inject } from 'vue';
import { GeneratorButtonVue } from '@/springboot/primary/generator/generator-button';
import { SetupService } from '@/springboot/domain/SetupService';
import { ProjectToUpdate, toProject } from '@/springboot/primary/ProjectToUpdate';
import { AlertBus } from '@/common/domain/alert/AlertBus';

export default defineComponent({
name: 'SetupGeneratorComponent',
Expand All @@ -13,7 +16,22 @@ export default defineComponent({
required: true,
},
},
setup() {
return {};
setup(props) {
const alertBus = inject('alertBus') as AlertBus;
const setupService = inject('setupService') as SetupService;

const selectorPrefix = 'setup-generator';
const addGithubActions = async (): Promise<void> => {
if (props.project.folder !== '') {
await setupService
.addGithubActions(toProject(props.project as ProjectToUpdate))
.then(() => alertBus.success('Github actions successfully added'))
.catch(error => alertBus.error(`Adding Github actions to project failed ${error}`));
}
};
return {
selectorPrefix,
addGithubActions,
};
},
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<template>
<div id="v-pills-setup" class="tab-pane fade" role="tabpanel" aria-labelledby="v-pills-profile-tab">
<div class="d-flex flex-column gap-3"></div>
<div>
<GeneratorButtonVue
:label="'Github Actions'"
:service="'github-actions'"
:selector-prefix="selectorPrefix"
@click.prevent="addGithubActions"
/>
</div>
</div>
</template>

Expand Down
15 changes: 15 additions & 0 deletions src/main/webapp/app/springboot/secondary/SetupRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { SetupService } from '@/springboot/domain/SetupService';
import { AxiosHttp } from '@/http/AxiosHttp';
import { ProjectHistoryService } from '@/common/domain/ProjectHistoryService';
import { RestProject, toRestProject } from '@/springboot/secondary/RestProject';
import { Project } from '@/springboot/domain/Project';

export default class SetupRepository implements SetupService {
constructor(private axiosHttp: AxiosHttp, private projectHistoryService: ProjectHistoryService) {}
private async postAndGetHistory(url: string, restProject: RestProject): Promise<void> {
await this.axiosHttp.post(url, restProject).then(() => this.projectHistoryService.get(restProject.folder));
}
async addGithubActions(project: Project): Promise<void> {
await this.postAndGetHistory('api/developer-tools/github-actions', toRestProject(project));
}
}
3 changes: 3 additions & 0 deletions src/test/javascript/cypress/integration/Generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const generatorSelector = (name: string) => dataSelector(composeSelector('genera
const headerSelector = (name: string) => dataSelector(composeSelector('header', name));
const projectGeneratorSelector = (name: string) => dataSelector(composeSelector('project-generator', name));
const springBootGeneratorSelector = (name: string) => dataSelector(composeSelector('spring-boot-generator', name));
const setupGeneratorSelector = (name: string) => dataSelector(composeSelector('setup-generator', name));
const angularGeneratorSelector = (name: string) => dataSelector(composeSelector('angular-generator', name));
const reactGeneratorSelector = (name: string) => dataSelector(composeSelector('react-generator', name));
const vueGeneratorSelector = (name: string) => dataSelector(composeSelector('vue-generator', name));
Expand Down Expand Up @@ -33,6 +34,8 @@ describe('Generator', () => {

it('should display setup', () => {
cy.get(dataSelector('section-setup')).contains('SETUP');

cy.get(setupGeneratorSelector('add-github-actions-button')).contains('Github Actions');
});

it('should display spring boot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('RestServiceId', () => {
expect(toService('flyway')).toEqual<Service>(Service.FLYWAY);
expect(toService('flyway-user-and-authority-changelogs')).toEqual<Service>(Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS);
expect(toService('frontend-maven-plugin')).toEqual<Service>(Service.FRONTEND_MAVEN_PLUGIN);
expect(toService('github-actions')).toEqual<Service>(Service.GITHUB_ACTIONS);
expect(toService('init')).toEqual<Service>(Service.INITIALIZATION);
expect(toService('jacoco-check-min-coverage')).toEqual<Service>(Service.JACOCO_CHECK_MINIMAL_COVERAGE);
expect(toService('java-base')).toEqual<Service>(Service.JAVA_BASE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { SetupService } from '../../../../../main/webapp/app/springboot/domain/SetupService';
import sinon, { SinonStub } from 'sinon';

export interface SetupServiceFixture extends SetupService {}
export interface SetupServiceFixture extends SetupService {
addGithubActions: SinonStub;
}

export const stubSetupService = (): SetupServiceFixture => ({});
export const stubSetupService = (): SetupServiceFixture => ({
addGithubActions: sinon.stub(),
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('ServiceProjection', () => {
'flyway-with-users-and-authority-changelogs'
);
expect(toServiceProjection(Service.FRONTEND_MAVEN_PLUGIN)).toEqual<ServiceProjection>('frontend-maven-plugin');
expect(toServiceProjection(Service.GITHUB_ACTIONS)).toEqual<ServiceProjection>('github-actions');
expect(toServiceProjection(Service.INITIALIZATION)).toEqual<ServiceProjection>('initialization');
expect(toServiceProjection(Service.JACOCO_CHECK_MINIMAL_COVERAGE)).toEqual<ServiceProjection>('jacoco-check-minimal-coverage');
expect(toServiceProjection(Service.JAVA_BASE)).toEqual<ServiceProjection>('java-base');
Expand Down Expand Up @@ -88,6 +89,7 @@ describe('ServiceProjection', () => {
Service.FLYWAY_WITH_USERS_AND_AUTHORITY_CHANGELOGS
);
expect(fromServiceProjection('frontend-maven-plugin')).toEqual<Service>(Service.FRONTEND_MAVEN_PLUGIN);
expect(fromServiceProjection('github-actions')).toEqual<Service>(Service.GITHUB_ACTIONS);
expect(fromServiceProjection('initialization')).toEqual<Service>(Service.INITIALIZATION);
expect(fromServiceProjection('jacoco-check-minimal-coverage')).toEqual<Service>(Service.JACOCO_CHECK_MINIMAL_COVERAGE);
expect(fromServiceProjection('java-base')).toEqual<Service>(Service.JAVA_BASE);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { shallowMount, VueWrapper } from '@vue/test-utils';
import { AlertBus } from '@/common/domain/alert/AlertBus';
import { ProjectToUpdate } from '@/springboot/primary/ProjectToUpdate';
import { stubAlertBus } from '../../../../common/domain/AlertBus.fixture';
import { AlertBusFixture, stubAlertBus } from '../../../../common/domain/AlertBus.fixture';
import { createProjectToUpdate } from '../../ProjectToUpdate.fixture';
import { stubSetupService } from '../../../domain/SetupService.fixture';
import { SetupService } from '@/springboot/domain/SetupService';
import { SetupGeneratorVue } from '@/springboot/primary/generator/setup-generator';
import { stubSpringBootService } from '../../../domain/SpringBootService.fixture';
import { projectJson } from '../RestProject.fixture';
import { set } from 'husky';

let wrapper: VueWrapper;
let component: any;
Expand Down Expand Up @@ -35,10 +38,52 @@ const wrap = (wrapperOptions?: Partial<WrapperOptions>) => {
});
component = wrapper.vm;
};
const expectAlertErrorToBe = (alertBus: AlertBusFixture, message: string) => {
const [alertMessage] = alertBus.error.getCall(0).args;
expect(alertMessage).toBe(message);
};
const expectAlertSuccessToBe = (alertBus: AlertBusFixture, message: string) => {
const [alertMessage] = alertBus.success.getCall(0).args;
expect(alertMessage).toBe(message);
};
describe('SetupGenerator', () => {
it('should exist', () => {
wrap();

expect(wrapper.exists()).toBe(true);
});

it('should not add Github Actions when project path is not filled', async () => {
const setupService = stubSetupService();
setupService.addGithubActions.resolves({});
await wrap({ setupService, project: createProjectToUpdate({ folder: '' }) });

await component.addGithubActions();

expect(setupService.addGithubActions.called).toBe(false);
});

it('should add Github Actions when project path is filled', async () => {
const setupService = stubSetupService();
setupService.addGithubActions.resolves({});
const alertBus = stubAlertBus();
await wrap({ alertBus, setupService, project: createProjectToUpdate({ folder: 'project/path' }) });

await component.addGithubActions();

const args = setupService.addGithubActions.getCall(0).args[0];
expect(args).toEqual(projectJson);
expectAlertSuccessToBe(alertBus, 'Github actions successfully added');
});

it('should handle error on adding github actions failure', async () => {
const setupService = stubSetupService();
setupService.addGithubActions.rejects('error');
const alertBus = stubAlertBus();
await wrap({ alertBus, setupService, project: createProjectToUpdate({ folder: 'project/path' }) });

await component.addGithubActions();

expectAlertErrorToBe(alertBus, 'Adding Github actions to project failed error');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ describe('ProjectRepository', () => {
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});

it('should download the project', async () => {
const projectHistoryService = stubProjectHistoryService();
const axiosHttpStub = stubAxiosHttp();
Expand Down Expand Up @@ -211,7 +210,7 @@ describe('ProjectRepository', () => {
const projectHistoryService = stubProjectHistoryService();
const axiosHttpStub = stubAxiosHttp();
const projectStoreStub = stubProjectStore();
const project: Project = createProject({ folder: PROJECT_FOLDER });

axiosHttpStub.get.rejects();
const projectRepository = new ProjectRepository(axiosHttpStub, projectHistoryService, projectStoreStub);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { stubProjectHistoryService } from '../../common/domain/ProjectHistoryService.fixture';
import { stubAxiosHttp } from '../../http/AxiosHttpStub';
import { Project } from '../../../../../main/webapp/app/springboot/domain/Project';
import { createProject } from '../domain/Project.fixture';
import { RestProject, toRestProject } from '../../../../../main/webapp/app/springboot/secondary/RestProject';
import SetupRepository from '../../../../../main/webapp/app/springboot/secondary/SetupRepository';

const PROJECT_FOLDER = 'folder/path';

describe('SetupRepository', () => {
it('should add Github actions', async () => {
const projectHistoryService = stubProjectHistoryService();
const axiosHttpStub = stubAxiosHttp();
axiosHttpStub.post.resolves();
const setupRepository = new SetupRepository(axiosHttpStub, projectHistoryService);
const project: Project = createProject({ folder: PROJECT_FOLDER });

await setupRepository.addGithubActions(project);

const expectedRestProject: RestProject = toRestProject(project);
const [uri, payload] = axiosHttpStub.post.getCall(0).args;
expect(uri).toBe('api/developer-tools/github-actions');
expect(payload).toEqual<RestProject>(expectedRestProject);
const [projectFolder] = projectHistoryService.get.getCall(0).args;
expect(projectFolder).toBe(PROJECT_FOLDER);
});
});

0 comments on commit 9aed517

Please sign in to comment.