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

Add get jira issues #3 #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
out
node_modules
node_modules
.vscode
23 changes: 17 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@
"Other"
],
"activationEvents": [
"onCommand:extension.jiraCommit"
"onCommand:extension.jiraCommit",
"onCommand:extension.jiraTasks",
"onCommand:extension.jiraDoTasks"
],
"main": "./out/src/extension",
"contributes": {
"commands": [
{
"command": "extension.jiraCommit",
"title": "jira issue add git commit as comment"
}
{
"command": "extension.jiraCommit",
"title": "jira issue add git commit as comment"
},
{
"command": "extension.jiraTasks",
"title": "jira show tasks"
},
{
"command": "extension.jiraDoTasks",
"title": "jira do task"
}
]
},
"scripts": {
Expand All @@ -41,6 +51,7 @@
"vscode": "^0.11.0"
},
"dependencies": {
"copy-paste": "^1.3.0",
"jira-client": "^3.0.2"
}
}
}
106 changes: 47 additions & 59 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,70 @@

import * as vscode from 'vscode';
import * as cp from 'child_process';
import * as historyUtil from './historyUtils';
import * as path from 'path';
import * as fs from 'fs';
let JiraApi = require('jira-client');

import { JiraClient } from './jira';
import { QuickPickItem } from 'vscode';
import { Handler } from './handler';

const Copy = require('copy-paste');


export function activate(context: vscode.ExtensionContext) {


console.log('Congratulations, your extension "jira" is now active!');
let commits: any[];
let cwd = vscode.workspace.rootPath;
let issueNumber: string;
let commits: any[],
cwd = vscode.workspace.rootPath,
issueNumber: string,
jiraConfDir: string = path.join(cwd,'.vscode','jira.json'),
client: JiraClient = null;

fs.stat(jiraConfDir, function (err, stats) {
if (err === null) {
let jiraConfig = require(jiraConfDir);
client = new JiraClient(jiraConfig);
if (!client.server) {
Handler.error('ERROR: can not get jira host at config file');
}
Handler.setClient(client);
} else {
Handler.error('ERROR: no config file at' + `${cwd}/.vscode/jira.json`);
}
});

let comment = vscode.commands.registerCommand('extension.jiraCommit', () => {
if (!client.isConnection()) {
Handler.error('ERROR: can not connect jira host');
return;
}
Handler.addCommentForIssue();
});

let tasks = vscode.commands.registerCommand("extension.jiraTasks", () => {
if (!client.isConnection()) {
Handler.error('ERROR: can not connect jira host');
return;
}
Handler.getMyIssues(function(data) {
if (data) {
Copy.copy(`${data.label} ${data.detail}`, function () {
vscode.window.setStatusBarMessage('The issue is copied.', 2000);
});
}
});
});

let jira_conf_Dir = path.join(cwd,'.vscode','jira.json');
let jira_conf = require(jira_conf_Dir);
// console.log(jira_conf['host']);

if (jira_conf['host'] !== undefined) {
vscode.window.showInputBox({ placeHolder: 'ID of a Issue' }).then((data) => {
if ((data !== undefined) && (data !== null)) {
issueNumber = data;

historyUtil.getGitRepositoryPath(vscode.window.activeTextEditor.document.fileName).then((gitRepositoryPath) => {

historyUtil.gitLog(gitRepositoryPath, []).then((log) => {
commits = log;
let comment: string;
let items = [];
for (let l in log) {
items.push(log[l].message)
}
let options = { matchOnDescription: false, placeHolder: "select Commit" };

vscode.window.showQuickPick(items, options).then((data) => {

comment = historyUtil.parseLog(commits[items.indexOf(data)]);

console.log(comment);

let jira = new JiraApi(jira_conf);

jira.findIssue(issueNumber).then((issue) => {
jira.addComment(issueNumber, comment).then((ret) => {
console.log(ret);

}).catch((err) => {
console.error(err);
vscode.window.showErrorMessage(`ERROR: comment Issue ${issueNumber}: ${err}`);
});
}).catch((err) => {
vscode.window.showErrorMessage(`ERROR: Issue ${issueNumber} not found!`);
});
})

}, (err) => {
vscode.window.showErrorMessage('ERROR: ' + err);
});


}, (err) => {
vscode.window.showErrorMessage('ERROR: ' + err);
});
}
})
} else {
vscode.window.showErrorMessage('ERROR: no config file at' + `${cwd}/.vscode/jira.json`);
let doTask = vscode.commands.registerCommand("extension.jiraDoTasks", () => {
if (!client.isConnection()) {
Handler.error('ERROR: can not connect jira host');
return;
}
Handler.doMyIssue();
});

context.subscriptions.push(comment);
context.subscriptions.concat([comment, tasks, doTask]);
}

// this method is called when your extension is deactivated
Expand Down
Loading