-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
GitHub app auth #21
GitHub app auth #21
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,3 +94,5 @@ typings/ | |
|
||
# End of https://www.gitignore.io/api/node | ||
xunit.xml | ||
|
||
github-app.pem |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:14 | ||
FROM node:16 | ||
|
||
ENV NODE_ENV production | ||
ENV PORT 3000 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,28 @@ | |
*/ | ||
|
||
const { Octokit } = require("@octokit/rest"); | ||
const { createAppAuth } = require('@octokit/auth-app'); | ||
const { request } = require("@octokit/request"); | ||
|
||
const GITHUB_TOKEN = process.env.GITHUB_TOKEN || 'invalid-dummy-secret'; | ||
const APP_ID = process.env.GITHUB_APP_ID; | ||
const PRIVATE_KEY = process.env.GITHUB_APP_PRIVATE_KEY; | ||
|
||
const INSTALLATION_ID = process.env.GITHUB_APP_INSTALLATION_ID || 22187127 | ||
|
||
async function getRestClient() { | ||
return new Octokit({ | ||
authStrategy: createAppAuth, | ||
auth: { | ||
appId: APP_ID, | ||
privateKey: PRIVATE_KEY, | ||
installationId: INSTALLATION_ID | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
commitExists: async (owner, repo, ref) => { | ||
let github = new Octokit({ | ||
auth: GITHUB_TOKEN | ||
}); | ||
const github = await getRestClient(); | ||
/* | ||
* Ensure that the commit is actually present in our repository! No sense | ||
* doing any work with it if it's somehow not published. | ||
|
@@ -22,18 +36,20 @@ module.exports = { | |
return !!commit; | ||
}, | ||
|
||
createStatus: async (owner, repo, sha, target_url) => { | ||
let github = new Octokit({ | ||
auth: GITHUB_TOKEN | ||
}); | ||
return github.repos.createCommitStatus({ | ||
createStatus: async (owner, repo, head_sha, entries) => { | ||
const github = await getRestClient(); | ||
return github.rest.checks.create({ | ||
owner, | ||
repo, | ||
sha, | ||
state: 'success', | ||
target_url, | ||
description: 'Deployed to Incrementals.', | ||
context: 'continuous-integration/jenkins/incrementals' | ||
name: 'Incrementals', | ||
head_sha, | ||
status: 'completed', | ||
conclusion: 'success', | ||
details_url: entries[0].url, | ||
output: { | ||
title: 'Deployed to Incrementals', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should pick text that is more self-descriptive for people who do not already know what this means? Somehow indicating that this snapshot-ish build is available for download or consumption from Maven in draft PRs, linking to jenkins.io docs, etc. |
||
summary: entries.map(entry => `- [${entry.artifactId}](${entry.url})`).join('\n') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And a good follow-up would be to show <dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>stuff</artifactId>
<version>1.2-rcdead1234beef</version>
</dependency>
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
}); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this also looks like a change. Your changing from a commit status to a check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, so I can get multi modules giving all links, was horrid UX for jenkins core before and others you had to replace the first modules artifact id with the one you wanted in the URL, it never got the hpi / war
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had filed an issue to this effect somewhere. Maybe only jenkins-infra/helpdesk#2426.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There we go, https://issues.jenkins.io/browse/JENKINS-52116 (CC @oleg-nenashev).