-
-
Notifications
You must be signed in to change notification settings - Fork 367
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't check for same user ID on comment when running as a GitHub App #525
Conversation
For peril? You should be setting the user ID otherwise it'll delete Danger messages that came from the CI as well This should be pretty easy to fix in Peril - just need to spend some time on danger/peril#179 |
I'm not using Peril. I use Danger as part of our CircleCI build. PS: The latest Travis CI build failed but the previous one was fine. The only difference is the addition of an entry in the changelog. Can you relaunch the build and see if it passes this time 😉? |
Oh yeah, sorry, yeah - I think this makes sense 👍 |
OK, that green'd |
@tibdex can you write how did you guys manage to run danger with the Github App? I'm struggling with that for a while. Do you get your app token before initializing danger? |
We do it like this: // Danger requires a DANGER_GITHUB_API_TOKEN environment property to work.
// Since we use a GitHub App to interact with the repository, there is an intermediate
// step which is to convert the GitHub App private key to an access token.
// We use fetch-github-app for that.
'use strict';
require('loud-rejection/register');
const envalid = require('envalid');
const execa = require('execa');
const fetchGithubApp = require('fetch-github-app');
const findYarnWorkspaceRoot = require('find-yarn-workspace-root');
const env = envalid.cleanEnv(
process.env, // eslint-disable-line no-process-env
{
DANGER_GITHUB_APP_ID: envalid.num({
desc:
'Can be found in the "GitHub Apps" section of the organization settings.',
}),
// Using base64 encoding in order not to deal with cumbersome EOL escaping.
// eslint-disable-next-line id-match
DANGER_GITHUB_APP_PEM_BASE64_ENCODED: envalid.makeValidator(str => {
const privateKey = Buffer.from(str, 'base64').toString('utf8');
if (
/-----BEGIN RSA PRIVATE KEY-----[\s\S]+-----END RSA PRIVATE KEY-----/m.test(
privateKey,
)
) {
return privateKey;
}
throw new Error('invalid GitHub App RSA private key');
})({
docs:
'https://developer.github.com/apps/building-integrations/setting-up-and-registering-github-apps/registering-github-apps/#generating-a-private-key',
}),
DANGER_GITHUB_INSTALLATION_ID: envalid.num({
desc:
'Can be found in the "Installed GitHub Apps" section of the organization settings',
}),
},
{strict: true},
);
fetchGithubApp({
appId: env.DANGER_GITHUB_APP_ID,
// Using base64 encoding in order not to deal with cumbersome EOL escaping.
appPrivateKey: env.DANGER_GITHUB_APP_PEM_BASE64_ENCODED,
installationId: env.DANGER_GITHUB_INSTALLATION_ID,
userAgent: 'activeviam',
}).then(({installationAccessToken}) =>
execa(
'danger',
['--dangerfile', 'danger/dangerfile.js', ...process.argv.slice(2)],
{
// Extend the environment of the child process with the access token.
env: {DANGER_GITHUB_API_TOKEN: installationAccessToken},
// To display Danger output in the console.
stdio: 'inherit',
cwd: findYarnWorkspaceRoot(),
},
),
); Instead of |
Sweet, thanks a lot! |
I wonder if that could be moved into a custom command in danger-js? |
Thanks @tibdex , that code above was useful. Currently using |
I think the line was wrongly changed here.
The consequence is that when running as a GitHub App, Danger will keep creating new comments instead of updating the existing one.