Skip to content

Commit 84273d2

Browse files
committed
✨ Add logic & layout
1 parent fddca52 commit 84273d2

File tree

14 files changed

+111
-48
lines changed

14 files changed

+111
-48
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { PuzzlePiece } from '@strapi/icons';
1+
import { Server } from '@strapi/icons';
22

3-
const PluginIcon = () => <PuzzlePiece />;
3+
const PluginIcon = () => <Server />;
44

55
export { PluginIcon };

admin/src/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
import { getTranslation } from './utils/getTranslation';
21
import { PLUGIN_ID } from './pluginId';
32
import { Initializer } from './components/Initializer';
43
import { PluginIcon } from './components/PluginIcon';
54

65
export default {
76
register(app) {
87
app.addMenuLink({
9-
to: `plugins/${PluginIcon}`,
8+
to: `plugins/${PLUGIN_ID}`,
109
icon: PluginIcon,
1110
intlLabel: {
1211
id: `${PLUGIN_ID}.plugin.name`,
13-
defaultMessage: PLUGIN_ID,
12+
defaultMessage: 'GitLab Publish',
1413
},
1514
Component: async () => {
1615
const { App } = await import('./pages/App');

admin/src/pages/HomePage.jsx

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,69 @@
1-
import { Main } from '@strapi/design-system';
2-
import { useIntl } from 'react-intl';
1+
import React, { useState } from 'react';
2+
import { PLUGIN_ID } from '../pluginId';
33

4-
import { getTranslation } from '../utils/getTranslation';
4+
import { useFetchClient, useNotification } from '@strapi/strapi/admin';
5+
import { Layouts, Page } from '@strapi/strapi/admin';
6+
import { Button } from '@strapi/design-system';
57

68
const HomePage = () => {
7-
const { formatMessage } = useIntl();
9+
const { toggleNotification } = useNotification();
10+
const { get } = useFetchClient();
11+
const [busy, setBusy] = useState(false);
12+
13+
const triggerPublish = async () => {
14+
if (busy === true) return;
15+
16+
setBusy(true);
17+
try {
18+
const { data } = await get(`/${PLUGIN_ID}/publish`);
19+
if (data?.success !== true) {
20+
handleError({ message: 'call not succeded' });
21+
} else {
22+
handleSuccess();
23+
}
24+
} catch (e) {
25+
handleError(e);
26+
}
27+
};
28+
29+
const handleSuccess = () => {
30+
toggleNotification({
31+
type: 'success',
32+
message: 'Pipeline launched ! Check it on GitLab to see progress.',
33+
});
34+
};
35+
36+
const handleError = (e) => {
37+
toggleNotification({
38+
type: 'danger',
39+
message: `Error during process : ${e.message}`,
40+
});
41+
setBusy(false);
42+
throw new Error(e);
43+
};
844

945
return (
10-
<Main>
11-
<h1>Welcome to {formatMessage({ id: getTranslation('plugin.name') })}</h1>
12-
</Main>
46+
<Layouts.Root>
47+
<Page.Title children={'GitLab Publish'} />
48+
<Page.Main>
49+
<Layouts.Header
50+
title={'GitLab Publish'}
51+
subtitle={'Trigger GitLab pipeline in one click !'}
52+
/>
53+
54+
<Layouts.Content>
55+
<Button
56+
onClick={triggerPublish}
57+
startIcon={null}
58+
type="button"
59+
variant="primary"
60+
disabled={busy === true}
61+
>
62+
Deploy
63+
</Button>
64+
</Layouts.Content>
65+
</Page.Main>
66+
</Layouts.Root>
1367
);
1468
};
1569

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"dependencies": {
3030
"@strapi/design-system": "^2.0.0-rc.14",
3131
"@strapi/icons": "^2.0.0-rc.14",
32+
"axios": "^1.7.9",
3233
"react-intl": "^7.1.0"
3334
},
3435
"devDependencies": {

pnpm-lock.yaml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/src/config/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
export default {
22
default: {},
3-
validator() {},
3+
validator: ({ project_id, project_pipeline_token, project_branch }) => {
4+
if (!project_id) {
5+
throw new Error('project_id is a required');
6+
}
7+
if (!project_pipeline_token) {
8+
throw new Error('project_pipeline_token is a required');
9+
}
10+
if (!project_branch) {
11+
throw new Error('project_branch is a required');
12+
}
13+
},
414
};

server/src/content-types/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

server/src/controllers/controller.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1+
import axios from 'axios';
2+
3+
const pluginId = 'plugin.gitlab-publish';
4+
15
const controller = ({ strapi }) => ({
2-
index(ctx) {
3-
ctx.body = strapi
4-
.plugin('gitlab-publish')
5-
// the name of the service file & the method.
6-
.service('service')
7-
.getWelcomeMessage();
6+
publish: async (ctx) => {
7+
const { project_id, project_pipeline_token, project_branch } = strapi.config.get(pluginId);
8+
9+
const headers = {
10+
'Content-Type': 'application/json',
11+
};
12+
13+
const url = `https://gitlab.com/api/v4/projects/${project_id}/ref/${project_branch}/trigger/pipeline?token=${project_pipeline_token}`;
14+
15+
const { status } = await axios.post(url, {}, { headers });
16+
const success = status === 201;
17+
18+
ctx.send({ success });
819
},
920
});
1021

server/src/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@ import register from './register';
99
* Plugin server methods
1010
*/
1111
import config from './config';
12-
import contentTypes from './content-types';
1312
import controllers from './controllers';
14-
import middlewares from './middlewares';
15-
import policies from './policies';
1613
import routes from './routes';
17-
import services from './services';
1814

1915
export default {
2016
bootstrap,
@@ -23,9 +19,5 @@ export default {
2319

2420
config,
2521
controllers,
26-
contentTypes,
27-
middlewares,
28-
policies,
2922
routes,
30-
services,
3123
};

server/src/middlewares/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)