Skip to content

Commit

Permalink
print github context
Browse files Browse the repository at this point in the history
  • Loading branch information
Oscar Franco committed Dec 3, 2020
1 parent 968a239 commit 6bbd727
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ async function run() {
'You have to set the GITHUB_CONTEXT in your configuration'
);
}

if (!process.env.GITHUB_TOKEN || process.env.GITHUB_TOKEN.length === 0) {
throw new Error('You have to set the GITHUB_TOKEN in your configuration');
}
Expand All @@ -25,6 +26,8 @@ async function run() {
process.env.GITHUB_CONTEXT || ''
) as GitHubContext<{}>;

core.info(`github context: ${process.env.GITHUB_CONTEXT}`);

await runTest();

const [owner, repo] = context.repository.split('/');
Expand Down Expand Up @@ -59,7 +62,6 @@ async function run() {
});

if (core.getInput('post-comment') === 'true' && testSummary) {
core.info('should post comment')
await createComment({
context,
comment: testSummary.text
Expand Down
35 changes: 13 additions & 22 deletions src/utils/createComment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GitHubContext } from './GithubContext';
import { github } from './Github';
import * as core from '@actions/core';

export async function createComment<E>({
context,
Expand All @@ -10,26 +9,18 @@ export async function createComment<E>({
comment: string;
}) {
const [owner, repo] = context.repository.split('/');
try {
core.info(`trying to post comment: ${comment}, sha: ${context.sha}`);
const res = await github.repos.createCommitComment({
body: comment,
commit_sha: context.sha,
owner,
repo
});
core.info(`Tried to post to PR: ${JSON.stringify(res, null, 4)}`)

core.info(`trying to post comment2 ${context.head_ref}`);
const res2 = await github.repos.createCommitComment({
body: comment,
commit_sha: context.head_ref,
owner,
repo,
});
// why is the sha not correct? sha is not the commit sha
// const res = await github.repos.createCommitComment({
// body: comment,
// commit_sha: context.sha,
// owner,
// repo
// });

core.info(`Tried to post to PR: ${JSON.stringify(res2, null, 4)}`)
} catch(error) {
core.info(`could not post comment, ${error}`)
}
await github.repos.createCommitComment({
body: comment,
commit_sha: context.head_ref,
owner,
repo,
});
}

0 comments on commit 6bbd727

Please sign in to comment.