diff --git a/.gitignore b/.gitignore
index 6704566..a38fe52 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+# User configuration
+prefs.plist
+
# Logs
logs
*.log
diff --git a/index.js b/index.js
index 972c2dc..95c4a6f 100644
--- a/index.js
+++ b/index.js
@@ -1,5 +1,10 @@
import alfy from 'alfy'
import { Octokit } from '@octokit/rest'
+
+const filename = process.env.JSON_FILENAME
+const nwo = process.env.GITHUB_NWO
+const token = process.env.GITHUB_TOKEN
+
const octokit = getOctokit()
try {
@@ -12,27 +17,28 @@ try {
}
function checkEnv () {
- if (!process.env.GITHUB_JSON_FILENAME ||
- !process.env.GITHUB_REPO ||
- !process.env.GITHUB_TOKEN) {
- throw new Error('Required workflow environment variables missing (GITHUB_JSON_FILENAME, GITHUB_REPO, and GITHUB_TOKEN). Please set them in your workflow settings.')
+ if (!filename || !nwo || !token) {
+ throw new Error('Required workflow user configuration missing (JSON_FILENAME, GITHUB_NWO, and GITHUB_TOKEN). Please set them in your workflow settings.')
}
}
function getOctokit () {
return new Octokit({
- auth: process.env.GITHUB_TOKEN
+ auth: token
})
}
async function getRemoteLinks () {
- const [owner, repo] = process.env.GITHUB_REPO.split('/') || ['imjohnbo', 'ghLinks-example']
- const path = process.env.GITHUB_JSON_FILENAME || 'ghLinks.json'
+ const [owner, repo] = nwo.split('/')
+
+ if (!owner || !repo) {
+ throw new Error('GitHub repo name with owner must be in format owner/repo, e.g. monalisa/hello-world.')
+ }
const { data: ghLinks } = await octokit.repos.getContent({
owner,
repo,
- path,
+ path: filename,
mediaType: {
format: 'raw'
}
diff --git a/info.plist b/info.plist
index b087eb7..03bc9c1 100644
--- a/info.plist
+++ b/info.plist
@@ -634,19 +634,70 @@ Community support available at https://github.com/imjohnbo/ghLinks.alfred. Enjoy
userconfigurationconfig
-
- variables
-
- GITHUB_JSON_FILENAME
-
- GITHUB_REPO
-
- GITHUB_TOKEN
-
-
- variablesdontexport
- GITHUB_TOKEN
+
+ config
+
+ default
+
+ placeholder
+ ghLinks.json
+ required
+
+ trim
+
+
+ description
+ The name of the JSON file containing links
+ label
+ JSON Filename
+ type
+ textfield
+ variable
+ JSON_FILENAME
+
+
+ config
+
+ default
+
+ placeholder
+ imjohnbo/ghLinks
+ required
+
+ trim
+
+
+ description
+ The GitHub repository containing JSON_FILENAME
+ label
+ GitHub repo name with owner
+ type
+ textfield
+ variable
+ GITHUB_NWO
+
+
+ config
+
+ default
+
+ placeholder
+ github_pat_123alongpersonalaccesstoken_replaceme456
+ required
+
+ trim
+
+
+ description
+ GitHub token (personal access token, installation access token, etc.) to access API
+ label
+ GitHub token
+ type
+ textfield
+ variable
+ GITHUB_TOKEN
+
version
0.0.1