Skip to content

Commit

Permalink
🎨
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Nov 10, 2022
1 parent 607d3bb commit a89975d
Show file tree
Hide file tree
Showing 10 changed files with 1,425 additions and 1,290 deletions.
2 changes: 1 addition & 1 deletion Finish.omnifocusjs/Resources/finish.js
Expand Up @@ -82,7 +82,7 @@
}
});
action.validate = function (selection, sender) {
return (selection.tasks.length === 1 && !selection.tasks[0].hasChildren);
return selection.tasks.length === 1 && !selection.tasks[0].hasChildren;
};
return action;
})();
60 changes: 41 additions & 19 deletions Finish.omnifocusjs/Resources/finish.ts
@@ -1,10 +1,13 @@
(() => {
var action = new PlugIn.Action(async (selection: Selection, sender: any) => {
try {
let originalTask = selection.tasks[0]
let originalTask = selection.tasks[0];
originalTask.flagged = false;

let isDoneAlert = new Alert("Is this task completely done?", originalTask.name);
let isDoneAlert = new Alert(
"Is this task completely done?",
originalTask.name
);
isDoneAlert.addOption("Yep!");
isDoneAlert.addOption("Not quite");
isDoneAlert.addOption("Whoops, never mind!");
Expand All @@ -20,7 +23,10 @@
let currentSibling = originalTask;

while (true) {
let nextThingAlert = new Alert("Is there anything that has to happen next?", currentSibling.name);
let nextThingAlert = new Alert(
"Is there anything that has to happen next?",
currentSibling.name
);
nextThingAlert.addOption("Yep!");
nextThingAlert.addOption("No, we're all done");

Expand All @@ -30,34 +36,44 @@
}

let nextSiblingForm = new Form();
nextSiblingForm.addField(new Form.Field.String("name", "What's Next?"));
nextSiblingForm.addField(
new Form.Field.String("name", "What's Next?")
);
nextSiblingForm.addField(new Form.Field.String("note", "Notes"));
await nextSiblingForm.show(`What's the next thing that needs to happen after "${currentSibling.name}"?`, "Save");
await nextSiblingForm.show(
`What's the next thing that needs to happen after "${currentSibling.name}"?`,
"Save"
);

var values = nextSiblingForm.values as { name: string, note: string }
var values = nextSiblingForm.values as { name: string; note: string };

currentSibling = new Task(values.name, currentSibling.after);
currentSibling.note = values.note;
currentSibling.addTags(originalTask.tags);
}

} else if (isDoneAnswer == 1) {
/////////////////////////////
// No, it's not quite done //
/////////////////////////////
let nextThingForm = new Form();
nextThingForm.addField(new Form.Field.String("name", "What's Next?"));
nextThingForm.addField(new Form.Field.String("note", "Notes"));
await nextThingForm.show(`What's the next thing that needs to happen to finish "${originalTask.name}"?`, "Save");
await nextThingForm.show(
`What's the next thing that needs to happen to finish "${originalTask.name}"?`,
"Save"
);

var values = nextThingForm.values as { name: string, note: string }
var values = nextThingForm.values as { name: string; note: string };

let currentSibling = new Task(values.name, originalTask.beginning);
currentSibling.note = values.note;
currentSibling.addTags(originalTask.tags);

while (true) {
let nextThingAlert = new Alert("Is there anything that'd have to happen after this is done?", currentSibling.name);
let nextThingAlert = new Alert(
"Is there anything that'd have to happen after this is done?",
currentSibling.name
);
nextThingAlert.addOption("Yep!");
nextThingAlert.addOption("No, not for now");

Expand All @@ -67,38 +83,44 @@
}

let nextSiblingForm = new Form();
nextSiblingForm.addField(new Form.Field.String("name", "What's Next?"));
nextSiblingForm.addField(
new Form.Field.String("name", "What's Next?")
);
nextSiblingForm.addField(new Form.Field.String("note", "Notes"));
await nextSiblingForm.show(`What's the next thing that needs to happen after "${currentSibling.name}"?`, "Save");
await nextSiblingForm.show(
`What's the next thing that needs to happen after "${currentSibling.name}"?`,
"Save"
);

values = nextSiblingForm.values as { name: string, note: string }
values = nextSiblingForm.values as { name: string; note: string };

currentSibling = new Task(values.name, currentSibling.after);
currentSibling.note = values.note;
currentSibling.addTags(originalTask.tags);
}

} else if (isDoneAnswer == 2) {
///////////////////////////////////////
// Whoops, didn't mean to click that //
///////////////////////////////////////
return;

} else {
/////////////////////////////////////////
// We forgot how many answers we added //
/////////////////////////////////////////
new Alert("Whoops!", `I got a value of '${isDoneAnswer}' from that alert, but I'm not sure what that means. This is a plugin bug!`)
new Alert(
"Whoops!",
`I got a value of '${isDoneAnswer}' from that alert, but I'm not sure what that means. This is a plugin bug!`
);
return;
}
} catch (err) {
console.error(err);
}
});

action.validate = function(selection: Selection, sender: any){
return (selection.tasks.length === 1 && !selection.tasks[0].hasChildren)
action.validate = function (selection: Selection, sender: any) {
return selection.tasks.length === 1 && !selection.tasks[0].hasChildren;
};

return action;
})();
12 changes: 7 additions & 5 deletions GitHub.omnifocusjs/Resources/pull.js
Expand Up @@ -33,23 +33,25 @@
req.bodyString = `{"query":"{ search(type: ISSUE, query: \\"is:issue assignee:${login} state:open\\", last: 100) { nodes { ... on Issue { number title body url repository { name owner { login } } } } } }"}`;
req.headers = {
"Content-Type": "application/json",
"Authorization": `bearer ${key}`,
Authorization: `bearer ${key}`,
};
let resp = await (req.fetch().catch((err) => {
let resp = await req.fetch().catch((err) => {
console.error("Problem fetching issues:", err);
let alert = new Alert("Problem fetching from GitHub", err);
alert.show();
throw err;
}));
});
if (resp.bodyString === null) {
throw "body string was null. Did the request succeed?";
}
let body = JSON.parse(resp.bodyString);
let toFocus = [];
for (let issue of body.data.search.nodes) {
let gitHubTag = flattenedTags.byName("from GitHub") || new Tag("from GitHub");
let orgTag = gitHubTag.tagNamed(issue.repository.owner.login) || new Tag(issue.repository.owner.login, gitHubTag);
let repoTag = orgTag.tagNamed(issue.repository.name) || new Tag(issue.repository.name, orgTag);
let orgTag = gitHubTag.tagNamed(issue.repository.owner.login) ||
new Tag(issue.repository.owner.login, gitHubTag);
let repoTag = orgTag.tagNamed(issue.repository.name) ||
new Tag(issue.repository.name, orgTag);
let repo = `${issue.repository.owner.login}/${issue.repository.name}`;
let projectName = `${repo}#${issue.number}: ${issue.title}`;
let project = flattenedProjects.byName(projectName) || new Project(projectName);
Expand Down
210 changes: 112 additions & 98 deletions GitHub.omnifocusjs/Resources/pull.ts
@@ -1,102 +1,116 @@
(() => {
let creds = new Credentials();

var action = new PlugIn.Action(async () => {
try {
let req = URL.FetchRequest.fromString("https://api.github.com/graphql");
if (req === null || req.url === null || req.url.host === null) {
throw "could not parse the URL for GitHub's GraphQL API"
}

/////////////////////////////////////
// Step 1: make sure we have creds //
/////////////////////////////////////
let stored = creds.read(req.url.host);

let login = null;
let key = null;

if (stored === null || app.optionKeyDown) {
let credsForm = new Form();
credsForm.addField(new Form.Field.String("login", "Login"));
credsForm.addField(new Form.Field.Password("key", "API Key"));

await credsForm.show("Let's set up: we need your GitHub username and an API key with the\n`repo` permission to pull issues from your assigned repos.\n\nCreate this at https://github.com/settings/tokens\n\nYou can get back here in the future to rotate tokens by holding\noption while activating the workflow.", "Save Key");
login = (credsForm.values as { login: string }).login;
key = (credsForm.values as { key: string }).key;

creds.write(req.url.host, login, key);
} else {
login = stored.user;
key = stored.password;
}

////////////////////////////
// Step 2: get the issues //
////////////////////////////
req.method = "POST";
req.bodyString = `{"query":"{ search(type: ISSUE, query: \\"is:issue assignee:${login} state:open\\", last: 100) { nodes { ... on Issue { number title body url repository { name owner { login } } } } } }"}`;
req.headers = {
"Content-Type": "application/json",
"Authorization": `bearer ${key}`,
};

let resp = await (req.fetch().catch((err) => {
console.error("Problem fetching issues:", err);
let alert = new Alert("Problem fetching from GitHub", err);
alert.show();
throw err;
}));

if (resp.bodyString === null) {
throw "body string was null. Did the request succeed?"
}

let body = JSON.parse(resp.bodyString);

//////////////////////////////////
// Step 3: make the tasks in OF //
//////////////////////////////////
type Issue = {
number: number,
title: string,
body: string,
url: string,
repository: {
name: string,
owner: {
login: string,
},
},
};

let toFocus: Array<Project> = [];
for (let issue of body.data.search.nodes as Issue[]) {
let gitHubTag = flattenedTags.byName("from GitHub") || new Tag("from GitHub");
let orgTag = gitHubTag.tagNamed(issue.repository.owner.login) || new Tag(issue.repository.owner.login, gitHubTag);
let repoTag = orgTag.tagNamed(issue.repository.name) || new Tag(issue.repository.name, orgTag);

let repo = `${issue.repository.owner.login}/${issue.repository.name}`;
let projectName = `${repo}#${issue.number}: ${issue.title}`;
let project = flattenedProjects.byName(projectName) || new Project(projectName);
project.addTag(repoTag);
project.note = `${issue.url}\n\n---\n\n${issue.body}`;
toFocus.push(project);

if (project.tasks.length === 0) {
new Task(`what needs to be done for ${repo}#${issue.number}?`, project);
}
}

if (app.platformName === "macOS") {
document.windows[0].perspective = Perspective.BuiltIn.Projects;
document.windows[0].focus = toFocus as SectionArray;
}
} catch (err) {
console.error(err);
throw err;
let creds = new Credentials();

var action = new PlugIn.Action(async () => {
try {
let req = URL.FetchRequest.fromString("https://api.github.com/graphql");
if (req === null || req.url === null || req.url.host === null) {
throw "could not parse the URL for GitHub's GraphQL API";
}

/////////////////////////////////////
// Step 1: make sure we have creds //
/////////////////////////////////////
let stored = creds.read(req.url.host);

let login = null;
let key = null;

if (stored === null || app.optionKeyDown) {
let credsForm = new Form();
credsForm.addField(new Form.Field.String("login", "Login"));
credsForm.addField(new Form.Field.Password("key", "API Key"));

await credsForm.show(
"Let's set up: we need your GitHub username and an API key with the\n`repo` permission to pull issues from your assigned repos.\n\nCreate this at https://github.com/settings/tokens\n\nYou can get back here in the future to rotate tokens by holding\noption while activating the workflow.",
"Save Key"
);
login = (credsForm.values as { login: string }).login;
key = (credsForm.values as { key: string }).key;

creds.write(req.url.host, login, key);
} else {
login = stored.user;
key = stored.password;
}

////////////////////////////
// Step 2: get the issues //
////////////////////////////
req.method = "POST";
req.bodyString = `{"query":"{ search(type: ISSUE, query: \\"is:issue assignee:${login} state:open\\", last: 100) { nodes { ... on Issue { number title body url repository { name owner { login } } } } } }"}`;
req.headers = {
"Content-Type": "application/json",
Authorization: `bearer ${key}`,
};

let resp = await req.fetch().catch((err) => {
console.error("Problem fetching issues:", err);
let alert = new Alert("Problem fetching from GitHub", err);
alert.show();
throw err;
});

if (resp.bodyString === null) {
throw "body string was null. Did the request succeed?";
}

let body = JSON.parse(resp.bodyString);

//////////////////////////////////
// Step 3: make the tasks in OF //
//////////////////////////////////
type Issue = {
number: number;
title: string;
body: string;
url: string;
repository: {
name: string;
owner: {
login: string;
};
};
};

let toFocus: Array<Project> = [];
for (let issue of body.data.search.nodes as Issue[]) {
let gitHubTag =
flattenedTags.byName("from GitHub") || new Tag("from GitHub");

let orgTag =
gitHubTag.tagNamed(issue.repository.owner.login) ||
new Tag(issue.repository.owner.login, gitHubTag);

let repoTag =
orgTag.tagNamed(issue.repository.name) ||
new Tag(issue.repository.name, orgTag);

let repo = `${issue.repository.owner.login}/${issue.repository.name}`;
let projectName = `${repo}#${issue.number}: ${issue.title}`;
let project =
flattenedProjects.byName(projectName) || new Project(projectName);
project.addTag(repoTag);
project.note = `${issue.url}\n\n---\n\n${issue.body}`;
toFocus.push(project);

if (project.tasks.length === 0) {
new Task(
`what needs to be done for ${repo}#${issue.number}?`,
project
);
}
});
}

if (app.platformName === "macOS") {
document.windows[0].perspective = Perspective.BuiltIn.Projects;
document.windows[0].focus = toFocus as SectionArray;
}
} catch (err) {
console.error(err);
throw err;
}
});

return action;
return action;
})();

0 comments on commit a89975d

Please sign in to comment.