Skip to content

Instantly share code, notes, and snippets.

@pasikonik
Last active July 11, 2019 09:00
Show Gist options
  • Save pasikonik/adeb556b6a9061b23afb49da7bff1424 to your computer and use it in GitHub Desktop.
Save pasikonik/adeb556b6a9061b23afb49da7bff1424 to your computer and use it in GitHub Desktop.
async function detectTaskAnProject({ getters, dispatch }) {
let projects = getters['project/projects'];
if (!projects.length) {
projects = await dispatch('project/fetch');
}
const tab = await getTabInfo();
const system = await detectSystem(projects, tab);
const project = await detectProject(projects, system.id);
let task = {};
try {
task = system.id ? await detectTask(system, tab) : { ticketUrl: tab.url };
} catch (e) {
return { project: { id: project.id } };
}
return dispatch('task/add', {
project: { id: project.id },
projectSystemId: system.id,
externalId: task.ticketId,
externalUrl: task.ticketUrl,
description: task.ticketDescription,
title: (task.ticketTitle && system.id ? task.ticketTitle : tab.content.title),
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment