Skip to content

Commit

Permalink
Merge pull request #16 from ljay79/develop
Browse files Browse the repository at this point in the history
v0.14.0 - GAS v8
  • Loading branch information
ljay79 authored Jun 27, 2017
2 parents 1deddf6 + 7d4f613 commit 93f38bb
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 28 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ You can directly import entire issue lists with your Jira filters just from with
Enter your Jira server domain and user details once, and be able to use the Jira features in any sheet at any time.
No manual status update copy&paste anymore.

> Tested with latest Jira Cloud (OnDemand) - compatibility with Jira Server not yet fully tested! Please provide feedback.
# Install / Get started
* Open up your chrome browser
* Find & Install the Add-on "[Jira Sheet Tools](https://chrome.google.com/webstore/detail/jira-sheet-tools/ncijnapilmmnebhbdanhkbbofofcniao)"
Expand Down Expand Up @@ -41,6 +43,9 @@ Simply provide your individual Jira server settings before you use all features.
In any Google sheet, go in the menu to “Add-ons" > "Jira Sheet Tools" > "Settings”.
Enter your "Jira Domain", "Username" and "Password".

> It is recommended to use this Add-on only with an Jira Cloud/Server instance which runs via SSL (https).
> This Add-on is using simple Basic Auth mechanism to authenticate with Jira, which means, user credentials are transmitted unsecure when using without SSL.
**You're all set and ready to go**

# Features
Expand Down
2 changes: 1 addition & 1 deletion dialogAbout.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<div class="block head">
<span class="icon"><img src="https://s3.eu-central-1.amazonaws.com/jira-tools/symbol.png" width="50" height="50" /></span>
<span class="title">Jira Sheet Tools v0.13.0</span>
<span class="title">Jira Sheet Tools v0.14.0</span>
</div>

<div class="block about">
Expand Down
10 changes: 7 additions & 3 deletions dialogs.gs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ function getServerCfg() {
* @return {object} Object({status: [boolean], response: [string]})
*/
function saveSettings(jsonFormData) {
var url = trimChar(jsonFormData.jira_url, "/");
setCfg('available', false);
setCfg('jira_url', trimChar(jsonFormData.jira_url, "/"));
setCfg('jira_url', url);
setCfg('jira_username', jsonFormData.jira_username);
setCfg('jira_password', jsonFormData.jira_password);

var test = testConnection();

if (url.indexOf('atlassian.net') == -1) {
setCfg('server_type', 'server');
}

return {status: test.status, message: test.response};
}
Expand All @@ -88,10 +93,9 @@ function dialogRefreshTicketsIds() {
function dialogIssueFromFilter() {
if(!hasSettings(true)) return;

var userProps = PropertiesService.getUserProperties();
var dialog = getDialog('dialogIssuesFromFilter', {
columns: ISSUE_COLUMNS,
defaultColumns: JSON.parse(userProps.getProperty('jiraColumnDefault'))
defaultColumns: JSON.parse(getVar('jiraColumnDefault'))
});

dialog
Expand Down
27 changes: 19 additions & 8 deletions jiraApi.gs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
* @object
*/
var restMethods = {
'dashboard': '/dashboard',
'issueStatus': {method: '/issue/{issueIdOrKey}', queryparams:{fields: ['status']}},
'myFilters': {method: '/filter/my', queryparams: {includeFavourites: 'false'}},
'filter': {method: '/filter/{filterId}'},
//'search': {method: '/search', queryparams: {jql:'', fields: [], properties: [], maxResults: 100, validateQuery: 'strict'}} // GET
'search': {method: '/search'} // POST
'onDemand': {
'dashboard': '/dashboard',
'issueStatus': {method: '/issue/{issueIdOrKey}', queryparams:{fields: ['status']}},
'filter': {method: '/filter/{filterId}'},
//'search': {method: '/search', queryparams: {jql:'', fields: [], properties: [], maxResults: 100, validateQuery: 'strict'}} // GET
'search': {method: '/search'}, // POST
'myFilters': {method: '/filter/my', queryparams: {includeFavourites: 'false'}}
},
'server': {
'dashboard': '/dashboard',
'issueStatus': {method: '/issue/{issueIdOrKey}', queryparams:{fields: ['status']}},
'filter': {method: '/filter/{filterId}'},
'search': {method: '/search'}, // POST
// server api doesnt support /filter/my
'myFilters': {method: '/filter/favourite', queryparams: {includeFavourites: 'false'}}
}
};

var httpErrorCodes = {
Expand Down Expand Up @@ -135,8 +145,9 @@ function Request() {
return this;
}

jiraMethod = (typeof restMethods[method] === 'object') ? restMethods[method].method : restMethods[method];
jiraQueryParams = (typeof restMethods[method] === 'object') ? restMethods[method].queryparams : {};
var server_type = getCfg('server_type') || 'onDemand';
jiraMethod = (typeof restMethods[server_type][method] === 'object') ? restMethods[server_type][method].method : restMethods[server_type][method];
jiraQueryParams = (typeof restMethods[server_type][method] === 'object') ? restMethods[server_type][method].queryparams : {};

var fetchArgs = fetchArgs || {}, urlParams = {};
this.prepareParams(urlParams, jiraQueryParams);
Expand Down
77 changes: 61 additions & 16 deletions storage.gs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
// default issue fields/columns for issue listings
var jiraColumnDefault = [
'summary',
'issuetype',
'priority',
'status',
'updated',
'assignee',
'due',
'project'
];

/**
* @desc Helper to check if server settings are available
* @param alert {boolean} TRUE=prompts a Browser message box, FALSE=returns boolean
* @return {boolean}
*/
function hasSettings(alert) {
initDefaults();

var available = getCfg('available');
var url = getCfg('jira_url');
var username = getCfg('jira_username');
var password = getCfg('jira_password');

var jiraColumnDefault = getCfg('jiraColumnDefault');
if( jiraColumnDefault != null ) {
jiraColumnDefault = JSON.parse(jiraColumnDefault);
}
setCfg('jiraColumnDefault', JSON.stringify(jiraColumnDefault));

if(available === undefined || !username || !password || !url) {
if(alert) Browser.msgBox("Jira Error",
"Please configure the Jira Settings first!\\n\\n" +
Expand Down Expand Up @@ -59,13 +67,50 @@ function getCfg(key) {
return userProps.getProperty('serverConfig.' + key);
}

// default issue fields/columns for issue listings
var jiraColumnDefault = [
'summary',
'issuetype',
'priority',
'status',
'updated',
'assignee',
'due'
];
/**
* @desc Short Helper to save a variable in the property storage
* @param key {string}
* @param value {string}
* @return {this} Allow chaining
*/
function setVar(key, value) {
var userProps = PropertiesService.getUserProperties();
userProps.setProperty(key, value);
return this;
}

/**
* @desc Short Helper to get a variable from property storage
* @param key {string}
* @return {string}||NULL
*/
function getVar(key) {
var userProps = PropertiesService.getUserProperties();
return userProps.getProperty(key);
}


/**
* @desc Storage init / setting defaults
* Google Guide states, we should not access property storage during onInstall or onOpen,
* So we have to do it somehow else, initializing some vars.
* Need better testing utilities or advice to improve this dirty workaround.
*
*/
function initDefaults() {
var isInitialized = getVar('defaults_initialized') || 'false';
if (isInitialized == 'true') return;

// set default jira issue columns
var columnDefaults = getVar('jiraColumnDefault');
columnDefaults = (columnDefaults != null) ? JSON.parse(columnDefaults) : jiraColumnDefault;
setVar('jiraColumnDefault', JSON.stringify(columnDefaults));

// Jira onDemand or Server
var server_type = getCfg('server_type');
if (server_type == null) server_type = 'onDemand';
setCfg('server_type', server_type);

// set done
setVar('defaults_initialized', 'true');
}

0 comments on commit 93f38bb

Please sign in to comment.