Skip to content

Commit

Permalink
Add placeholders, show created comment url
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Aug 13, 2021
1 parent ffa41da commit 17eb590
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 24 deletions.
36 changes: 20 additions & 16 deletions __tests__/classes/comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ describe('getRawBody', () => {

getRunContext(): RunContext {
const runContext: RunContext = {
Id: this.id,
ConfigFilePath: this.inputs.ConfigFilePath,
LabelName: this.labelName as string,
LabelEvent: this.labelEvent,
EventName: this.eventName,
EventAlias: this.eventAlias
Id: this.id,
EventAlias: this.eventAlias,
LabelEvent: this.labelEvent,
LabelName: this.labelName as string,
IssueNumber: this.issueNumber
};
return runContext;
}
Expand Down Expand Up @@ -320,12 +321,13 @@ describe('Mustache issues', () => {

getRunContext(): RunContext {
const runContext: RunContext = {
Id: this.id,
ConfigFilePath: this.inputs.ConfigFilePath,
LabelName: this.labelName as string,
LabelEvent: this.labelEvent,
EventName: this.eventName,
EventAlias: this.eventAlias
Id: this.id,
EventAlias: this.eventAlias,
LabelEvent: this.labelEvent,
LabelName: this.labelName as string,
IssueNumber: this.issueNumber
};
return runContext;
}
Expand Down Expand Up @@ -502,12 +504,13 @@ describe('Mustache pull_request', () => {

getRunContext(): RunContext {
const runContext: RunContext = {
Id: this.id,
ConfigFilePath: this.inputs.ConfigFilePath,
LabelName: this.labelName as string,
LabelEvent: this.labelEvent,
EventName: this.eventName,
EventAlias: this.eventAlias
Id: this.id,
EventAlias: this.eventAlias,
LabelEvent: this.labelEvent,
LabelName: this.labelName as string,
IssueNumber: this.issueNumber
};
return runContext;
}
Expand Down Expand Up @@ -684,12 +687,13 @@ describe('Mustache pull_request_target', () => {

getRunContext(): RunContext {
const runContext: RunContext = {
Id: this.id,
ConfigFilePath: this.inputs.ConfigFilePath,
LabelName: this.labelName as string,
LabelEvent: this.labelEvent,
EventName: this.eventName,
EventAlias: this.eventAlias
Id: this.id,
EventAlias: this.eventAlias,
LabelEvent: this.labelEvent,
LabelName: this.labelName as string,
IssueNumber: this.issueNumber
};
return runContext;
}
Expand Down
15 changes: 15 additions & 0 deletions src/classes/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ class Comment implements ICommentGenerator {
get view(): any {
if (this.runContext.EventName === 'issues') {
return {
eventName: this.runContext.EventName,
number: this.runContext.IssueNumber,
labelName: this.runContext.LabelName,
author: this.contextLoader.userLogin,
labeler: this.contextLoader.senderLogin,
issue: {
user: {
login: this.contextLoader.userLogin
Expand All @@ -116,6 +121,11 @@ class Comment implements ICommentGenerator {
};
} else if (this.runContext.EventName === 'discussion') {
return {
eventName: this.runContext.EventName,
number: this.runContext.IssueNumber,
labelName: this.runContext.LabelName,
author: this.contextLoader.userLogin,
labeler: this.contextLoader.senderLogin,
discussion: {
user: {
login: this.contextLoader.userLogin
Expand All @@ -130,6 +140,11 @@ class Comment implements ICommentGenerator {
this.runContext.EventName === 'pull_request_target'
) {
return {
eventName: this.runContext.EventName,
number: this.runContext.IssueNumber,
labelName: this.runContext.LabelName,
author: this.contextLoader.userLogin,
labeler: this.contextLoader.senderLogin,
pull_request: {
user: {
login: this.contextLoader.userLogin
Expand Down
17 changes: 10 additions & 7 deletions src/classes/context-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ const eventType = (eventName: EventName): EventAlias =>
eventTypeTable[eventName as keyof EventTypeTable];

interface RunContext {
readonly Id: string;
readonly ConfigFilePath: string;
readonly LabelName: string;
readonly LabelEvent: LabelEvent;

readonly EventName: EventName;
readonly Id: string;
readonly EventAlias: EventAlias;
readonly LabelEvent: LabelEvent;
readonly LabelName: string;
readonly IssueNumber: number;
}

interface IContext {
Expand Down Expand Up @@ -122,12 +124,13 @@ class ContextLoader implements IContextLoader {

getRunContext(): RunContext {
const runContext: RunContext = {
Id: this.id,
ConfigFilePath: this.inputs.ConfigFilePath,
LabelName: this.labelName as string,
LabelEvent: this.labelEvent,
EventName: this.eventName,
EventAlias: this.eventAlias
Id: this.id,
EventAlias: this.eventAlias,
LabelEvent: this.labelEvent,
LabelName: this.labelName as string,
IssueNumber: this.issueNumber
};
groupConsoleLog('Dump runContext', runContext);
return runContext;
Expand Down
4 changes: 3 additions & 1 deletion src/classes/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ class Issue implements IIssueProcessor {
addDiscussionComment(input: $input) {
comment {
body
id
url
}
}
}
Expand All @@ -215,7 +217,7 @@ class Issue implements IIssueProcessor {

try {
const res: GraphQlQueryResponseData = await this.githubClient.graphql(query, variables);
info(`Add comment to #${this.number}`);
info(`Add comment to #${this.number}, ${res.addDiscussionComment.comment.url}`);
groupConsoleLog('GraphQlQueryResponseData', res);
} catch (error) {
groupConsoleLog('Request failed', error.request);
Expand Down

0 comments on commit 17eb590

Please sign in to comment.