Created
October 5, 2021 13:22
-
-
Save dayhaysoos/6bb1fa07abf7410107e77a071b30e4e3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const { Octokit } = require('@octokit/rest') | |
const CLIENT_MAP = require('../utils/client-map') | |
exports.handler = async function (event, context) { | |
try { | |
const { queryStringParameters } = event | |
const companyName = CLIENT_MAP.get(queryStringParameters.code) | |
if (!companyName) { | |
return { | |
statusCode: 404, | |
body: JSON.stringify({ message: 'No company found for that code' }), | |
} | |
} | |
const octokit = new Octokit({ | |
auth: process.env.GITHUB_API_KEY, | |
}) | |
const isDevelopment = process.env.NETLIFY_DEV === 'true' | |
const branch = isDevelopment ? 'local-development-working-branch' : 'master' | |
const fileData = await octokit.repos.getContent({ | |
owner: process.env.GITHUB_OWNER, | |
ref: branch, | |
repo: 'blacktechpipeline.com', | |
path: `content/jobs/posts/${companyName}.md`, | |
}) | |
return { | |
statusCode: 200, | |
body: JSON.stringify({ message: fileData.data }), | |
} | |
} catch (error) { | |
return { | |
statusCode: 422, | |
body: JSON.stringify({ message: error.message }), | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment