Skip to content

Commit

Permalink
use environment variables instead of config dir
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Dec 18, 2024
1 parent 65640b4 commit c7cc040
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ package-lock.json
bin

data

# Local Netlify folder
.netlify
11 changes: 6 additions & 5 deletions netlify/functions/webhookGitHubComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
const axios = require('axios');
const createReleaseFromChangelog = require('../../src/actions/createReleaseFromChangelog');
const { createTokenAuth } = require('@octokit/auth-token');
const config = require('../../.config');
const connect = require('../../src/db');
const extrovert = require('extrovert');

const ignoreUsers = new Set(config.ignoreUsers);
const ignoreUsers = new Set((process.env.IGNORE_GITHUB_USERS || '').split(','));
const githubAccessTokenForMongoose = process.env.GITHUB_ACCESS_TOKEN_FOR_MONGOOSE;
const slackToken = process.env.SLACK_TOKEN;

module.exports = extrovert.toNetlifyFunction(async function webhookGitHubComment(params) {
const conn = await connect();
const Subscriber = conn.model('Subscriber');

const { token } = await createTokenAuth(config.githubAccessTokenForMongoose)();
const { token } = await createTokenAuth(githubAccessTokenForMongoose)();

const { action, issue, sender, ref, ref_type } = req.body;
const { action, issue, sender, ref, ref_type } = params;

if (action === 'opened' && issue != null) {
// Opened new issue
Expand Down Expand Up @@ -71,7 +72,7 @@ module.exports = extrovert.toNetlifyFunction(async function webhookGitHubComment
}
},
]
}, { headers: { authorization: `Bearer ${config.slackToken}` } });
}, { headers: { authorization: `Bearer ${slackToken}` } });
} else if (ref != null && ref_type === 'tag') {
// Assume tag was created, so create a release
await createReleaseFromChangelog(ref);
Expand Down
5 changes: 3 additions & 2 deletions src/db/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const config = require('../../.config');
const mongoose = require('mongoose');

let conn = null;
Expand All @@ -10,9 +9,11 @@ const jobSchema = require('./Job');
const subscriberSchema = require('./subscriber');
const taskSchema = require('./task');

const uri = process.env.MONGODB_CONNECTION_STRING;

module.exports = async function connect() {
if (conn == null) {
conn = mongoose.createConnection(config.uri);
conn = mongoose.createConnection(uri);
await conn.asPromise();
}
conn.model('AccessToken', accessTokenSchema, 'AccessToken');
Expand Down

0 comments on commit c7cc040

Please sign in to comment.