Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jira integration #2121

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/src/api/integration/helpers/jiraAuthenticate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Permissions from '../../../security/permissions'
import IntegrationService from '../../../services/integrationService'
import PermissionChecker from '../../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.tenantEdit)
const payload = await new IntegrationService(req).jiraConnectOrUpdate(req.body)
await req.responseHandler.success(req, res, payload)
}
38 changes: 38 additions & 0 deletions backend/src/api/integration/helpers/jiraAuthenticateValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import axios from 'axios';
import { Error400 } from '@crowd/common';
import Permissions from '../../../security/permissions';
import PermissionChecker from '../../../services/user/permissionChecker';

export default async (req, res) => {
new PermissionChecker(req).validateHasAny([
Permissions.values.integrationCreate,
Permissions.values.integrationEdit,
]);

const { jiraURL, jiraUsername, jiraUserToken } = req.body;

if (jiraURL) {
const headers: { Authorization?: string } = {};
if (jiraUsername && jiraUserToken) {
headers.Authorization = `Basic ${Buffer.from(`${jiraUsername}:${jiraUserToken}`).toString('base64')}`;
}

try {
// if (jiraUsername && jiraUserToken) {
// const userValidationEndpoint = `${jiraURL}/rest/api/2/myself`;
// const resultMyself = await axios.get(userValidationEndpoint, { headers });
// }

const projectEndpoint = `${jiraURL}/rest/api/2/project`;
const result = await axios.get(projectEndpoint, { headers });
if (result.status === 200 && result.data && result.data.length > 0) {
return req.responseHandler.success(req, res, result.data);
}

} catch (e) {
return req.responseHandler.error(req, res, new Error400(req.language));
}
}

return req.responseHandler.error(req, res, new Error400(req.language));
};
31 changes: 31 additions & 0 deletions backend/src/api/integration/helpers/jiraProjectValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import axios from 'axios';
import { Error400 } from '@crowd/common';
import Permissions from '../../../security/permissions';
import PermissionChecker from '../../../services/user/permissionChecker';

export default async (req, res) => {
new PermissionChecker(req).validateHasAny([
Permissions.values.integrationCreate,
Permissions.values.integrationEdit,
]);

const { jiraURL, jiraUsername, jiraUserToken,jiraProject } = req.body;
if (jiraURL) {
const endpoint = `${jiraURL}/rest/api/2/project/${jiraProject}`;
const headers: { Authorization?: string } = {};
if (jiraUsername && jiraUserToken) {
headers.Authorization = `Basic ${Buffer.from(`${jiraUsername}:${jiraUserToken}`).toString('base64')}`;
}

try {
const result = await axios.get(endpoint, { headers })
if (result.status === 200 && result.data) {
return req.responseHandler.success(req, res, result.data);
}
} catch (e) {
return req.responseHandler.error(req, res, new Error400(req.language))
}
}

return req.responseHandler.error(req, res, new Error400(req.language))
};
33 changes: 33 additions & 0 deletions backend/src/api/integration/helpers/jiraURLValidator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import axios from 'axios';
import { Error400 } from '@crowd/common'
import Permissions from '../../../security/permissions';
import PermissionChecker from '../../../services/user/permissionChecker';

export default async (req, res) => {
new PermissionChecker(req).validateHasAny([
Permissions.values.integrationCreate,
Permissions.values.integrationEdit,
]);

const { jiraURL, jiraUsername, jiraUserToken } = req.body;

if (jiraURL) {
const endpoint = `${jiraURL}/rest/api/2/serverInfo`;
const headers: { Authorization?: string } = {};
if (jiraUsername && jiraUserToken) {
headers.Authorization = `Basic ${Buffer.from(`${jiraUsername}:${jiraUserToken}`).toString('base64')}`;
}

try {
const result = await axios.get(endpoint, { headers })
if (result.status === 200 && result.data) {
return req.responseHandler.success(req, res, result.data);
}

} catch (e) {
return req.responseHandler.error(req, res, new Error400(req.language))
}
}

return req.responseHandler.error(req, res, new Error400(req.language))
};
16 changes: 16 additions & 0 deletions backend/src/api/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ export default (app) => {
`/tenant/:tenantId/confluence-connect`,
safeWrap(require('./helpers/confluenceAuthenticate').default),
)
app.put(
`/tenant/:tenantId/jira-connect`,
safeWrap(require('./helpers/jiraAuthenticate').default)
)
app.post(
'/tenant/:tenantId/jira-validate-url',
safeWrap(require('./helpers/jiraURLValidator').default),
)
app.post(
'/tenant/:tenantId/jira-validate-authenticate',
safeWrap(require('./helpers/jiraAuthenticateValidator').default),
)
app.post(
'/tenant/:tenantId/jira-validate-project',
safeWrap(require('./helpers/jiraProjectValidator').default),
)
app.put(
`/tenant/:tenantId/gerrit-connect`,
safeWrap(require('./helpers/gerritAuthenticate').default),
Expand Down
34 changes: 34 additions & 0 deletions backend/src/services/integrationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,40 @@ export default class IntegrationService {
return integration
}


/**
* Adds/updates Jira integration
* @param integrationData to create the integration object
* @returns integration object
*/
async jiraConnectOrUpdate(integrationData) {
const transaction = await SequelizeRepository.createTransaction(this.options)
let integration
try {
integration = await this.createOrUpdate(
{
platform: PlatformType.JIRA,
settings: {
//remotes: integrationData.remotes,
jiraURL: integrationData.jiraURL,
jiraUsername: integrationData.jiraUsername,
jiraUserToken: integrationData.jiraUserToken,
projects: integrationData.projects,
},
status: 'done',
},
transaction,
)

await SequelizeRepository.commitTransaction(transaction)
} catch (err) {
await SequelizeRepository.rollbackTransaction(transaction)
throw err
}
return integration
}


/**
* Adds/updates Gerrit integration
* @param integrationData to create the integration object
Expand Down
Binary file added frontend/public/images/integrations/jira.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const defaultConfig = {
isGitEnabled: import.meta.env.VUE_APP_IS_GIT_ENABLED,
isGroupsioEnabled: import.meta.env.VUE_APP_IS_GROUPSIO_ENABLED,
isConfluenceEnabled: import.meta.env.VUE_APP_IS_CONFLUENCE_ENABLED,
isJiraEnabled: import.meta.env.VUE_APP_IS_JIRA_ENABLED,
isGerritEnabled: import.meta.env.VUE_APP_IS_GERRIT_ENABLED,
isTwitterEnabled: import.meta.env.VUE_APP_IS_TWITTER_ENABLED,
};
Expand Down Expand Up @@ -123,6 +124,7 @@ const composedConfig = {
isGroupsioEnabled: 'CROWD_VUE_APP_IS_GROUPSIO_ENABLED',
isTwitterEnabled: 'CROWD_VUE_APP_IS_TWITTER_ENABLED',
isConfluenceEnabled: 'CROWD_VUE_APP_IS_CONFLUENCE_ENABLED',
isJiraEnabled: 'CROWD_VUE_APP_IS_JIRA_ENABLED',
isGerritEnabled: 'CROWD_VUE_APP_IS_GERRIT_ENABLED',
};

Expand All @@ -137,5 +139,6 @@ config.isGitIntegrationEnabled = config.isGitEnabled === 'true';
config.isGroupsioIntegrationEnabled = config.isGroupsioEnabled === 'true';
config.isTwitterIntegrationEnabled = config.isTwitterEnabled === 'true';
config.isConfluenceEnabled = config.isConfluenceEnabled === 'true';
config.isJiraEnabled = config.isJiraEnabled === 'true';

export default config;
2 changes: 2 additions & 0 deletions frontend/src/integrations/integrations-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import lfx from './custom/lfx';
import groupsio from './groupsio';
import confluence from './confluence';
import gerrit from './gerrit';
import jira from './jira';
import cvent from './custom/cvent';
import tnc from './custom/tnc';

Expand All @@ -44,6 +45,7 @@ class IntegrationsConfig {
// make,
facebook,
confluence,
jira,
gerrit,
};
}
Expand Down
Loading