Skip to content

Commit

Permalink
feat: move workflow environment variables to user configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
imjohnbo committed Aug 10, 2022
1 parent 31b463d commit 8e0da71
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# User configuration
prefs.plist

# Logs
logs
*.log
Expand Down
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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'
}
Expand Down
75 changes: 63 additions & 12 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,70 @@ Community support available at https://github.com/imjohnbo/ghLinks.alfred. Enjoy
</dict>
</dict>
<key>userconfigurationconfig</key>
<array/>
<key>variables</key>
<dict>
<key>GITHUB_JSON_FILENAME</key>
<string></string>
<key>GITHUB_REPO</key>
<string></string>
<key>GITHUB_TOKEN</key>
<string></string>
</dict>
<key>variablesdontexport</key>
<array>
<string>GITHUB_TOKEN</string>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string></string>
<key>placeholder</key>
<string>ghLinks.json</string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string>The name of the JSON file containing links</string>
<key>label</key>
<string>JSON Filename</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>JSON_FILENAME</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string></string>
<key>placeholder</key>
<string>imjohnbo/ghLinks</string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string>The GitHub repository containing JSON_FILENAME</string>
<key>label</key>
<string>GitHub repo name with owner</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>GITHUB_NWO</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string></string>
<key>placeholder</key>
<string>github_pat_123alongpersonalaccesstoken_replaceme456</string>
<key>required</key>
<true/>
<key>trim</key>
<true/>
</dict>
<key>description</key>
<string>GitHub token (personal access token, installation access token, etc.) to access API</string>
<key>label</key>
<string>GitHub token</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>GITHUB_TOKEN</string>
</dict>
</array>
<key>version</key>
<string>0.0.1</string>
Expand Down

0 comments on commit 8e0da71

Please sign in to comment.