-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// This script fetches your GitHub repos (sorted by most recently active), | ||
// and then presents a prompt to pick one. A new issue is then created in | ||
// that repo using the current draft's contents. | ||
// | ||
// NOTE: The first time you run this action you'll need to supply it with a | ||
// GitHub Personal Access Token that has read/write permissions to the repos | ||
// on your account. You can generate a token here: | ||
// https://github.com/settings/tokens | ||
|
||
let NumberOfRecentReposToFetch = 10; | ||
|
||
var credential = Credential.create("GitHub", "A GitHub Personal Access Token with read/write repo permissions."); | ||
credential.addTextField("token", "Personal Access Token"); | ||
credential.authorize(); | ||
|
||
let repos = getRecentRepos(); | ||
if (repos.length > 0) { | ||
let p = Prompt.create(); | ||
p.title = "Choose Repo"; | ||
for (var i = 0; i < repos.length; i++) { | ||
p.addButton(repos[i].full_name, i); | ||
} | ||
if (p.show()) { | ||
let full_name = repos[p.buttonPressed].full_name; | ||
createGitHubIssue(full_name, draft.title, draft.content); | ||
} | ||
} | ||
|
||
// Fetches the NumberOfRecentReposToFetch most recent repos | ||
// (both public and private) from the authorized GitHub account. | ||
function getRecentRepos() { | ||
var http = HTTP.create(); | ||
var response = http.request({ | ||
"url": "https://api.github.com/user/repos?sort=pushed&per_page=" + NumberOfRecentReposToFetch, | ||
"method": "GET", | ||
"headers": { | ||
"Authorization": "token " + credential.getValue("token"), | ||
"User-Agent": "Drafts-Issue-Bot" | ||
} | ||
}); | ||
return JSON.parse(response.responseText); | ||
} | ||
|
||
// Create a new GitHub issue in the repo identified by full_name, | ||
// which is in a "username/repo" format. | ||
function createGitHubIssue(full_name, title, body) { | ||
var json = { | ||
title: title, | ||
body: body | ||
}; | ||
|
||
var http = HTTP.create(); | ||
var response = http.request({ | ||
"url": "https://api.github.com/repos/" + full_name + "/issues", | ||
"method": "POST", | ||
"data": json, | ||
"headers": { | ||
"Authorization": "token " + credential.getValue("token"), | ||
"User-Agent": "Drafts-Issue-Bot" | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// create credentials for site | ||
let cred = Credential.createWithHostUsernamePassword("WordPress", "WordPress credentials. Include full URL (with http://) of the home page of your WordPress site in the host field."); | ||
cred.authorize(); | ||
|
||
// create WordPress object and make request | ||
let wp = WordPress.create(cred.getValue("host"), 1, "", ""); | ||
let method = "wp.getPosts" | ||
let params = [ | ||
1, // blog_id, in most cases just use 1 | ||
cred.getValue("username"), | ||
cred.getValue("password") | ||
]; | ||
let response = wp.runMethod(method, params); | ||
|
||
if (response.success) { | ||
// I should have an array of post objects in first param | ||
let s = []; | ||
let posts = response.params[0]; | ||
for (let post of posts) { | ||
s.push(`- ${post.post_title} [link](${post.link})`); | ||
} | ||
let d = Draft.create(); | ||
d.content = s.join("\n"); | ||
d.update(); | ||
editor.load(d); | ||
} | ||
else { | ||
console.log("HTTP Status: " + response.statusCode); | ||
console.log("XML-RPC Fault: " + response.faultCode + ", " + response.error); | ||
context.fail(); | ||
} |