Skip to content

Commit

Permalink
adds Toggle to use Sprint name (#6)
Browse files Browse the repository at this point in the history
Co-authored-by: Tucker Bradford <[email protected]>
  • Loading branch information
mtuckerb and mtuckerb authored Dec 9, 2022
1 parent 17a0bbd commit 53f19b3
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/Clients/JiraClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ export interface JiraSettings {
name: string,
email: string,
apiToken: string,
boardId: string
boardId: string,
useSprintName: boolean
}

export const JIRA_DEFAULT_SETTINGS: JiraSettings = {
baseUrl: '{yourserver}.atlassian.net',
name: '',
email: '',
apiToken: '',
boardId: ''
boardId: '',
useSprintName: true,
}

export class JiraClient implements ITfsClient{
Expand All @@ -32,19 +34,25 @@ export class JiraClient implements ITfsClient{
"Authorization": `Basic ${encoded64Key}`,
"Content-Type": "application/json"
}

const BaseURL = `https://${settings.jiraSettings.baseUrl}/rest/agile/1.0`;

try {
const sprintsResponse = await requestUrl({ method: 'GET', headers: headers, url: `${BaseURL}/board/${settings.jiraSettings.boardId}/sprint?state=active` })

const currentSprintId = sprintsResponse.json.values[0].id;

const currentSprintId = sprintsResponse.json.values[0].id
const currentSprintName = sprintsResponse.json.values[0].name
.replace(/Sprint/, '')
.replace(/Board/, '')
.replace(/^\s+|\s+$/g, '')
.replace(/[^a-z0-9 -]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')

const sprintIdentifier = settings.jiraSettings.useSprintName ? currentSprintName : currentSprintId
const issuesResponse = await requestUrl({ method: 'GET', headers: headers, url: `${BaseURL}/board/${settings.jiraSettings.boardId}/sprint/${currentSprintId}/issue?jql=assignee=\"${settings.jiraSettings.name}\"` });

const assignedIssuesInSprint = issuesResponse.json.issues;

const normalizedFolderPath = normalizePath(settings.targetFolder + '/sprint-' + currentSprintId);
const normalizedFolderPath = normalizePath(settings.targetFolder + '/sprint-' + sprintIdentifier);

// Ensure folder structure created
VaultHelper.createFolders(normalizedFolderPath);
Expand All @@ -65,7 +73,7 @@ export class JiraClient implements ITfsClient{
const columnIds = boardConfigResponse.json.columnConfig.columns.map((column:any) => column.name);

// Create or replace Kanban board of current sprint
await VaultHelper.createKanbanBoard(normalizedFolderPath, tasks, columnIds, currentSprintId);
await VaultHelper.createKanbanBoard(normalizedFolderPath, tasks, columnIds, sprintIdentifier);
}

} catch(e) {
Expand Down Expand Up @@ -119,7 +127,16 @@ export class JiraClient implements ITfsClient{
plugin.settings.jiraSettings.apiToken = value;
await plugin.saveSettings();
}));

new Setting(container)
.setName('Use Sprint Name (rather than id)')
.setDesc("Uses the Sprint's human assigned name")
.addToggle(text => text
.setValue(plugin.settings.jiraSettings.useSprintName)
.onChange(async (value) => {
plugin.settings.jiraSettings.useSprintName = value;
await plugin.saveSettings();
})
);
new Setting(container)
.setName('Board ID')
.setDesc('The ID of your Scrum board (the number in the URL when viewing scrum board in browser) ')
Expand Down

0 comments on commit 53f19b3

Please sign in to comment.