Skip to content

Commit

Permalink
Revert "reopen closed discussions"
Browse files Browse the repository at this point in the history
This reverts commit 8e855bc.
  • Loading branch information
khushail committed Nov 11, 2023
1 parent 8e855bc commit 662119d
Show file tree
Hide file tree
Showing 11 changed files with 46,455 additions and 178 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/handle-stale-discussions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ jobs:
steps:
- name: Stale discussions action
uses: aws-github-ops/handle-stale-discussions@v1
with:
# This will close stale-discussions as outdated instead of answered
close-stale-as-answered: false
# This will disable auto-closing answered discussions
close-stale-as-outdated: false
# This will disable auto-closing answered discussions
close-answered-discussions: false
# This will disable auto-closing locked discussions
close-locked-discussions: false
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

3 changes: 0 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,3 @@ inputs:
page-size:
description: 'Page size count for discussions to be loaded per page'
required: false
open-discussion-instructions-text:
description: 'Comment to post when a discussion is opened'
required: false
18 changes: 1 addition & 17 deletions dist/GithubDiscussionClient.js

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions dist/generated/graphql.js

Large diffs are not rendered by default.

46,477 changes: 46,436 additions & 41 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/types/GithubDiscussionClient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ export declare class GithubDiscussionClient {
markDiscussionCommentAsAnswer(commentId: string): Promise<void>;
addAttentionLabelToDiscussion(discussionId: string): Promise<void>;
updateDiscussionComment(commentId: string, body: string): Promise<void>;
reopenDiscussion(discussionId: string): Promise<void>;
}
14 changes: 0 additions & 14 deletions dist/types/generated/graphql.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39132,7 +39132,6 @@ export declare const AddLabelToDiscussion: import("graphql").DocumentNode;
export declare const CloseDiscussionAsOutdated: import("graphql").DocumentNode;
export declare const CloseDiscussionAsResolved: import("graphql").DocumentNode;
export declare const MarkDiscussionCommentAsAnswer: import("graphql").DocumentNode;
export declare const ReopenDiscussion: import("graphql").DocumentNode;
export declare const UpdateDiscussionComment: import("graphql").DocumentNode;
export declare const GetAnswerableDiscussionId: import("graphql").DocumentNode;
export declare const GetCommentMetaData: import("graphql").DocumentNode;
Expand Down Expand Up @@ -39218,19 +39217,6 @@ export type MarkDiscussionCommentAsAnswerMutation = {
clientMutationId?: string | null;
} | null;
};
export type ReopenDiscussionMutationVariables = Exact<{
discussionId: Scalars['ID']['input'];
}>;
export type ReopenDiscussionMutation = {
__typename?: 'Mutation';
reopenDiscussion?: {
__typename?: 'ReopenDiscussionPayload';
discussion?: {
__typename?: 'Discussion';
id: string;
} | null;
} | null;
};
export type UpdateDiscussionCommentMutationVariables = Exact<{
commentId: Scalars['ID']['input'];
body: Scalars['String']['input'];
Expand Down
22 changes: 1 addition & 21 deletions src/GithubDiscussionClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import fetch from 'cross-fetch';
import { DiscussionConnection } from "@octokit/graphql-schema";
import { GetDiscussionCountQuery, GetDiscussionCountQueryVariables, GetDiscussionCount, GetDiscussionDataQuery, GetDiscussionDataQueryVariables, GetDiscussionData, GetAnswerableDiscussionIdQuery, GetAnswerableDiscussionIdQueryVariables, GetAnswerableDiscussionId, GetLabelIdQuery, GetLabelId, CloseDiscussionAsResolvedMutation, CloseDiscussionAsResolved, CloseDiscussionAsOutdatedMutation, CloseDiscussionAsOutdated, AddDiscussionCommentMutation, AddDiscussionComment, MarkDiscussionCommentAsAnswerMutation, MarkDiscussionCommentAsAnswer, AddLabelToDiscussionMutation, AddLabelToDiscussion, UpdateDiscussionCommentMutation, UpdateDiscussionComment, GetDiscussionCommentCountQuery, GetDiscussionCommentCount, DiscussionCommentConnection, GetCommentMetaDataQuery, GetCommentMetaDataQueryVariables, GetCommentMetaData, CloseDiscussionAsResolvedMutationVariables, CloseDiscussionAsOutdatedMutationVariables, AddDiscussionCommentMutationVariables, MarkDiscussionCommentAsAnswerMutationVariables, AddLabelToDiscussionMutationVariables, UpdateDiscussionCommentMutationVariables, GetDiscussionCommentCountQueryVariables, AddInstructionTextReplyMutation, AddInstructionTextReplyMutationVariables, AddInstructionTextReply, ReopenDiscussionMutation, ReopenDiscussionMutationVariables, ReopenDiscussion } from "./generated/graphql";
import { GetDiscussionCountQuery, GetDiscussionCountQueryVariables, GetDiscussionCount, GetDiscussionDataQuery, GetDiscussionDataQueryVariables, GetDiscussionData, GetAnswerableDiscussionIdQuery, GetAnswerableDiscussionIdQueryVariables, GetAnswerableDiscussionId, GetLabelIdQuery, GetLabelId, CloseDiscussionAsResolvedMutation, CloseDiscussionAsResolved, CloseDiscussionAsOutdatedMutation, CloseDiscussionAsOutdated, AddDiscussionCommentMutation, AddDiscussionComment, MarkDiscussionCommentAsAnswerMutation, MarkDiscussionCommentAsAnswer, AddLabelToDiscussionMutation, AddLabelToDiscussion, UpdateDiscussionCommentMutation, UpdateDiscussionComment, GetDiscussionCommentCountQuery, GetDiscussionCommentCount, DiscussionCommentConnection, GetCommentMetaDataQuery, GetCommentMetaDataQueryVariables, GetCommentMetaData, CloseDiscussionAsResolvedMutationVariables, CloseDiscussionAsOutdatedMutationVariables, AddDiscussionCommentMutationVariables, MarkDiscussionCommentAsAnswerMutationVariables, AddLabelToDiscussionMutationVariables, UpdateDiscussionCommentMutationVariables, GetDiscussionCommentCountQueryVariables, AddInstructionTextReplyMutation, AddInstructionTextReplyMutationVariables, AddInstructionTextReply } from "./generated/graphql";

export class GithubDiscussionClient {
private _githubClient: ApolloClient<NormalizedCacheObject>;
Expand Down Expand Up @@ -267,24 +267,4 @@ export class GithubDiscussionClient {
throw new Error(`Error updating discussion comment ${commentId}: ${result.errors}`);
}
}

public async reopenDiscussion(discussionId: string) {
try
{
const result = await this.githubClient.mutate<ReopenDiscussionMutation,ReopenDiscussionMutationVariables>({
mutation: ReopenDiscussion,
variables: {
discussionId
}
});

if (result.errors) {
throw new Error(`Error in reopening discussion ${discussionId}: ${result.errors}`);
}
}
catch(error)
{
core.warning(`Error in reopening discussion ${discussionId}: ${error}`);
}
}
}
16 changes: 0 additions & 16 deletions src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41413,15 +41413,6 @@ export const MarkDiscussionCommentAsAnswer = gql`
}
}
`;
export const ReopenDiscussion = gql`
mutation ReopenDiscussion($discussionId: ID!) {
reopenDiscussion(input: {discussionId: $discussionId}) {
discussion {
id
}
}
}
`;
export const UpdateDiscussionComment = gql`
mutation UpdateDiscussionComment($commentId: ID!, $body: String!) {
updateDiscussionComment(input: {commentId: $commentId, body: $body}) {
Expand Down Expand Up @@ -41611,13 +41602,6 @@ export type MarkDiscussionCommentAsAnswerMutationVariables = Exact<{

export type MarkDiscussionCommentAsAnswerMutation = { __typename?: 'Mutation', markDiscussionCommentAsAnswer?: { __typename?: 'MarkDiscussionCommentAsAnswerPayload', clientMutationId?: string | null } | null };

export type ReopenDiscussionMutationVariables = Exact<{
discussionId: Scalars['ID']['input'];
}>;


export type ReopenDiscussionMutation = { __typename?: 'Mutation', reopenDiscussion?: { __typename?: 'ReopenDiscussionPayload', discussion?: { __typename?: 'Discussion', id: string } | null } | null };

export type UpdateDiscussionCommentMutationVariables = Exact<{
commentId: Scalars['ID']['input'];
body: Scalars['String']['input'];
Expand Down
53 changes: 15 additions & 38 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import { GithubDiscussionClient } from "./GithubDiscussionClient";
import { containsKeyword, containsNegativeReaction, containsPositiveReaction, exceedsDaysUntilStale, hasReplies, triggeredByNewComment, hasNonBotReply } from './util';
import { DiscussionCommentEdge, MarkDiscussionCommentAsAnswer } from './generated/graphql';
import { DiscussionCommentEdge } from './generated/graphql';

const PAGE_SIZE = parseInt(core.getInput('page-size', { required: false })) || 50;
const GITHUB_BOT = core.getInput('github-bot', { required: false}) || 'github-actions';
Expand All @@ -18,12 +18,10 @@ const CLOSE_STALE_AS_ANSWERED = closeStaleAsAnsweredInput.toLowerCase() === 'fal
const CLOSE_FOR_STALENESS_RESPONSE_TEXT = core.getInput('stale-response-text', { required: false })
|| 'Closing the discussion for staleness. Please open a new discussion if you have further concerns.';
const INSTRUCTIONS_TEXT = core.getInput('instructions-response-text', { required: false })
|| 'Hello! A team member has suggested the above comment as the likely answer to this discussion thread. '
+ '\n \n * If you agree, please upvote that comment, or click on Mark as answer. I will automatically mark the discussion as answered with upvoted comment, next time I check. '
|| 'Hello! A team member has marked the above comment as the likely answer to this discussion thread. '
+ '\n \n * If you agree, please upvote that comment, or click on Mark as answer. I will automatically mark the comment as the answer next time I check. '
+ '\n \n * If this answer does not help you, please downvote the answer instead and let us know why it was not helpful. '
+ 'I will add a label to this discussion to gain attention from the team.';
const OPEN_DISCUSSION_INSTRUCTION_TEXT = core.getInput('open-discussion-instructions-text', { required: false })
|| 'Hello! Reopening discussion to make it searchable. ';

async function main() {
const githubClient = new GithubDiscussionClient();
Expand Down Expand Up @@ -59,15 +57,13 @@ export async function processDiscussions(githubClient: GithubDiscussionClient) {
for (const discussion of discussions.edges!) {
var discussionId = discussion?.node?.id ? discussion?.node?.id : "";
var discussionNum = discussion?.node?.number ? discussion.node.number : 0;
core.info(`Processing discussionId: ${discussionId} with number: ${discussionNum} and bodyText: ${discussion?.node?.bodyText}`);
core.debug(`Processing discussionId: ${discussionId} with number: ${discussionNum} and bodyText: ${discussion?.node?.bodyText}`);
if (discussionId === "" || discussionNum === 0) {
core.warning(`Can not proceed checking discussion, discussionId is null!`);
continue;
}
else if (discussion?.node?.closed) {
//core.debug(`Discussion ${discussionId} is closed, so no action needed.`);
core.info("Reopening closed discussion: ${discussionId}");
reopenClosedDiscussion(discussionId, githubClient);
core.debug(`Discussion ${discussionId} is closed, so no action needed.`);
continue;
}
else if (discussion?.node?.locked && CLOSE_LOCKED_DISCUSSIONS) {
Expand Down Expand Up @@ -97,13 +93,13 @@ export async function processComments(discussion: octokit.DiscussionEdge, github
if (commentCount !== 0) {
for (const comment of comments.edges!) {
const commentId = comment?.node?.id;
core.info(`Processing comment ${commentId} with bodytext: ${comment?.node?.bodyText}`);
core.debug(`Processing comment ${commentId} with bodytext: ${comment?.node?.bodyText}`);
if (!comment?.node?.bodyText || !comment.node.id) {
core.info(`Comment body or id is null in discussion ${discussionId}, skipping comment!`);
core.warning(`Comment body or id is null in discussion ${discussionId}, skipping comment!`);
continue;
}
if (!containsKeyword(comment!, PROPOSED_ANSWER_KEYWORD)) {
core.info(`No answer proposed on comment ${commentId}, no action needed!`);
core.debug(`No answer proposed on comment ${commentId}, no action needed!`);
continue;
}
else {
Expand All @@ -113,8 +109,7 @@ export async function processComments(discussion: octokit.DiscussionEdge, github
}
else if (containsPositiveReaction(comment)) {
core.info(`Positive reaction received. Marking discussion ${discussionId} as answered, and editing answer to remove proposed answer keyword`);
markDiscussionCommentAsAnswer(comment, discussionId, githubClient);
//closeAndMarkAsAnswered(comment, discussionId, githubClient);
closeAndMarkAsAnswered(comment, discussionId, githubClient);
}
else if (!hasReplies(comment)) {
core.info(`Since this has no reply, adding instructions reply to comment ${commentId} in discussion ${discussionId}`);
Expand All @@ -125,14 +120,12 @@ export async function processComments(discussion: octokit.DiscussionEdge, github
githubClient.addAttentionLabelToDiscussion(discussionId);
}
else if (exceedsDaysUntilStale(comment, DAYS_UNTIL_STALE)) {
if (!CLOSE_STALE_AS_ANSWERED) {
core.info(`No one has responded or provided a reaction, marking discussion ${discussionId} as answered`);
markDiscussionCommentAsAnswer(comment, discussionId, githubClient);
//closeAndMarkAsAnswered(comment, discussionId, githubClient);
}
else {
core.info(`No action needed for discussion ${discussionId}`);
//closeDiscussionForStaleness(discussionId, githubClient);
if (CLOSE_STALE_AS_ANSWERED) {
core.info(`No one has responded or provided a reaction, closing discussion ${discussionId} as answered`);
closeAndMarkAsAnswered(comment, discussionId, githubClient);
} else {
core.info(`No one has responded or provided a reaction, closing discussion ${discussionId} with a comment`);
closeDiscussionForStaleness(discussionId, githubClient);
}
}
}
Expand All @@ -148,8 +141,6 @@ function closeDiscussionForStaleness(discussionId: string, githubClient: GithubD
githubClient.closeDiscussionAsOutdated(discussionId);
}

//This functioon is no longer used since we are marking the discussion as answered instead of closing it
/*
function closeAndMarkAsAnswered(comment: DiscussionCommentEdge, discussionId: string, githubClient: GithubDiscussionClient) {
const bodyText = comment?.node?.bodyText!;
const commentId = comment?.node?.id!;
Expand All @@ -158,19 +149,5 @@ function closeAndMarkAsAnswered(comment: DiscussionCommentEdge, discussionId: st
githubClient.markDiscussionCommentAsAnswer(commentId);
githubClient.closeDiscussionAsResolved(discussionId);
}
*/

function markDiscussionCommentAsAnswer(comment: DiscussionCommentEdge, discussionId: string, githubClient: GithubDiscussionClient) {
const bodyText = comment?.node?.bodyText!;
const commentId = comment?.node?.id!;
const updatedAnswerText = bodyText.replace(PROPOSED_ANSWER_KEYWORD, 'Answer: ');
githubClient.updateDiscussionComment(commentId, updatedAnswerText);
githubClient.markDiscussionCommentAsAnswer(commentId);
}

function reopenClosedDiscussion(discussionId: string, githubClient: GithubDiscussionClient) {
githubClient.addCommentToDiscussion(discussionId, OPEN_DISCUSSION_INSTRUCTION_TEXT);
githubClient.reopenDiscussion(discussionId);
}

main();
7 changes: 0 additions & 7 deletions src/mutations/reopen-discussins.graphql

This file was deleted.

0 comments on commit 662119d

Please sign in to comment.