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

added jira cloud integration #980

Closed
wants to merge 7 commits into from
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
44 changes: 23 additions & 21 deletions app/components/jira-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ const JiraAccountComponent = Component.extend({
this.set('changeset', changeset);
},
didInsertElement() {
this._super(...arguments);
this._super(...arguments);
this.get('checkJIRA').perform();
},
baseURL: computed('organization.selected.id', '', function(){
baseURL: computed('organization.selected.id', '', function () {
return [
'/api/organizations',
this.get('organization.selected.id'), ENV.endpoints.integrateJira
Expand All @@ -52,34 +52,36 @@ this._super(...arguments);
this.get('revokeJIRA').perform();
},

checkJIRA: task(function *() {
checkJIRA: task(function* () {
try {
const data = yield this.get("ajax").request(this.get('baseURL'));
this.set("isJIRAConnected", true);
this.set("connectedHost", data.host);
this.set("connectedUsername", data.username);
} catch(error) {
if(error.status == 404) {
if (data.type == "jira") {
this.set("isJIRAConnected", true);
this.set("connectedHost", data.host);
this.set("connectedUsername", data.username);
}
} catch (error) {
if (error.status == 404) {
this.set("isJIRAConnected", false);
}
}
}).drop(),
revokeJIRA: task(function*(){
revokeJIRA: task(function* () {
try {
this.send("closeRevokeJIRAConfirmBox");
yield this.get("ajax").delete(this.get('baseURL'));
const tJiraWillBeRevoked = this.get("tJiraWillBeRevoked");
this.get("notify").success(tJiraWillBeRevoked);
this.get('checkJIRA').perform();
} catch(error) {
} catch (error) {
this.get("notify").error("Sorry something went wrong, please try again");
}
}).drop(),
integrateJIRA: task(function *(changeset){
integrateJIRA: task(function* (changeset) {
const tJiraIntegrated = this.get("tJiraIntegrated");
yield changeset.validate()
if(!changeset.get('isValid')) {
if(changeset.get('errors') && changeset.get('errors')[0].validation) {
if (!changeset.get('isValid')) {
if (changeset.get('errors') && changeset.get('errors')[0].validation) {
this.get("notify").error(
changeset.get('errors')[0].validation[0],
ENV.notifications
Expand All @@ -88,24 +90,24 @@ this._super(...arguments);
return;
}
const host = changeset.get('host').trim();
const username = changeset.get('username').trim();
const password = changeset.get('password');
const username = changeset.get('username').trim();
const password = changeset.get('password');
const data = {
host,
username,
password
};
try {
yield this.get("ajax").post(this.get('baseURL'), {data})
yield this.get("ajax").post(this.get('baseURL'), { data })
this.get('checkJIRA').perform();
this.get("notify").success(tJiraIntegrated);
triggerAnalytics('feature',ENV.csb.integrateJIRA);
} catch(error) {
if(error.payload) {
if(error.payload.host) {
triggerAnalytics('feature', ENV.csb.integrateJIRA);
} catch (error) {
if (error.payload) {
if (error.payload.host) {
this.get("notify").error(error.payload.host[0], ENV.notifications)
}
if(error.payload.username || error.payload.password) {
if (error.payload.username || error.payload.password) {
this.get("notify").error(this.get('tInValidCredentials'))
}
}
Expand Down
97 changes: 97 additions & 0 deletions app/components/jira-cloud-account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { computed } from '@ember/object';
import ENV from 'irene/config/environment';
import { on } from '@ember/object/evented';
import { t } from 'ember-intl';
import triggerAnalytics from 'irene/utils/trigger-analytics';
import { task } from 'ember-concurrency';

const JiraCloudAccountComponent = Component.extend({

intl: service(),
ajax: service('ajax'),
notify: service('notifications'),
organization: service('organization'),
isRevokingJIRA: false,
isJIRAConnected: false,
connectedHost: null,
tJiraWillBeRevoked: t("jiraWillBeRevoked"),
tJiraErrorIntegration: t("jiraErrorIntegration"),

integrateJiraURL: computed('organization.selected.id', '', function () {
return [
'/api/organizations',
this.get('organization.selected.id'), ENV.endpoints.integrateJira
].join('/')
}),

redirectAPI: task(function* () {
return yield this.get("ajax").request(
`/api/integrations/jira-cloud/${this.get('organization.selected.id')}/redirect/`
)
}),

integrateJiraCloud: task(function* () {
triggerAnalytics('feature', ENV.csb.integrateJIRACloud);
let data = yield this.get('redirectAPI').perform()
window.location.href = data.url;
}).evented(),

integrateJiraCloudErrored: on('integrateJiraCloud:errored', function () {
this.get("notify").error(this.get('tJiraErrorIntegration'));
}),

removeIntegrationUri: task(function* () {
return yield this.get("ajax").delete(this.get("integrateJiraURL"))
}),

didInsertElement() {
this._super(...arguments);
this.get('checkJIRA').perform();
},

checkJIRA: task(function* () {
try {
const data = yield this.get("ajax").request(this.get("integrateJiraURL"));
if (data.type == "jira_cloud_oauth") {
this.set("isJIRAConnected", true);
this.set("connectedHost", data.accounts)
}
} catch (error) {
if (error.status == 404) {
this.set("isJIRAConnected", false);
}
}
}).drop(),

removeIntegration: task(function* () {
yield this.get('removeIntegrationUri').perform()
this.get('checkJIRA').perform();
}).evented(),

removeIntegrationErrored: on('removeIntegration:errored', function (_, err) {
this.get("notify").error(err.payload.detail);
}),

removeIntegrationSucceded: on('removeIntegration:succeeded', function () {
this.get("notify").success(this.get("tJiraWillBeRevoked"));
this.send("closeRevokeJIRAConfirmBox");
}),

confirmCallback() {
this.get('removeIntegration').perform();
},

actions: {
openRevokeJIRAConfirmBox() {
this.set("showRevokeJIRAConfirmBox", true);
},

closeRevokeJIRAConfirmBox() {
this.set("showRevokeJIRAConfirmBox", false);
}
}
});

export default JiraCloudAccountComponent;
Loading