Skip to content

Commit

Permalink
Add AddComment GitHub action, and workflows for tagging new debugge…
Browse files Browse the repository at this point in the history
…r issues (#12496)
  • Loading branch information
Colengms authored Aug 20, 2024
1 parent 06ed838 commit 6324549
Show file tree
Hide file tree
Showing 15 changed files with 621 additions and 316 deletions.
70 changes: 70 additions & 0 deletions .github/actions/AddComment/AddComment.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions .github/actions/AddComment/AddComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { GitHub } from '../api/api';
import { ActionBase } from '../common/ActionBase';
import { daysAgoToHumanReadbleDate, daysAgoToTimestamp, safeLog } from '../common/utils';

This comment has been minimized.

Copy link
@dcmade01

dcmade01 Sep 20, 2024

add me on this i want to contribute


export class AddComment extends ActionBase {
constructor(
private github: GitHub,
private createdAfter: string,
private afterDays: number,
labels: string,
private addComment: string,
private addLabels?: string,
private removeLabels?: string,
private setMilestoneId?: string,
milestoneName?: string,
milestoneId?: string,
ignoreLabels?: string,
ignoreMilestoneNames?: string,
ignoreMilestoneIds?: string,
minimumVotes?: number,
maximumVotes?: number,
involves?: string
) {
super(labels, milestoneName, milestoneId, ignoreLabels, ignoreMilestoneNames, ignoreMilestoneIds, minimumVotes, maximumVotes, involves);
}

async run() {
const updatedTimestamp = this.afterDays ? daysAgoToHumanReadbleDate(this.afterDays) : undefined;
const query = this.buildQuery(
(updatedTimestamp ? `updated:<${updatedTimestamp} ` : "") +
(this.createdAfter ? `created:>${this.createdAfter} ` : "") +
"is:open is:unlocked");

const addLabelsSet = this.addLabels ? this.addLabels.split(',') : [];
const removeLabelsSet = this.removeLabels ? this.removeLabels.split(',') : [];

for await (const page of this.github.query({ q: query })) {
for (const issue of page) {
const hydrated = await issue.getIssue();
if (hydrated.open && this.validateIssue(hydrated)
// TODO: Verify updated timestamp
) {
if (this.addComment) {
safeLog(`Posting comment on issue ${hydrated.number}`);
await issue.postComment(this.addComment);
}
if (removeLabelsSet.length > 0) {
for (const removeLabel of removeLabelsSet) {
if (removeLabel && removeLabel.length > 0) {
safeLog(`Removing label on issue ${hydrated.number}: ${removeLabel}`);
await issue.removeLabel(removeLabel);
}
}
}
if (addLabelsSet.length > 0) {
for (const addLabel of addLabelsSet) {
if (addLabel && addLabel.length > 0) {
safeLog(`Adding label on issue ${hydrated.number}: ${addLabel}`);
await issue.addLabel(addLabel);
}
}
}
if (this.setMilestoneId != undefined) {
safeLog(`Setting milestone of issue ${hydrated.number} to id ${+this.setMilestoneId}`);
await issue.setMilestone(+this.setMilestoneId);
}
safeLog(`Processing issue ${hydrated.number}.`);
} else {
if (!hydrated.open) {
safeLog(`Issue ${hydrated.number} is not open. Ignoring`);
}
}
}
}
}
}
42 changes: 42 additions & 0 deletions .github/actions/AddComment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name:Add Comment and Label
description: Add comment (etc) to issues that are marked with a specified label (etc)
inputs:
token:
description: GitHub token with issue, comment, and label read/write permissions
default: ${{ github.token }}
createdAfter:
description: Creation date after which to be considered.
required: false
afterDays:
description: Days to wait before performing this action (may be 0).
required: false
addComment:
description: Comment to add
labels:
description: items with these labels will be considered. May be "*".
required: true
milestoneName:
description: items with these milestones will be considered (name only, must match ID)
milestoneId:
description: items with these milestones will be considered (id only, must match name)
ignoreLabels:
description: items with these labels will not be considered
ignoreMilestoneNames:
description: items with these milestones will not be considered (names only, must match IDs). May be "*".
ignoreMilestoneIds:
description: items with these milestones will not be considered (IDs only, must match names)
addLabels:
description: Labels to add to issue.
removeLabels:
description: Labels to remove from issue.
minimumVotes:
descriptions: Only issues with at least this many votes will be considered.
maximumVotes:
descriptions: Only issues fewer or equal to this many votes will be considered.
involves:
descriptions: Qualifier to find issues that in some way involve a certain user either as an author, assignee, or mentions.
readonly:
description: If true, changes are not applied.
runs:
using: 'node12'
main: 'index.js'
20 changes: 20 additions & 0 deletions .github/actions/AddComment/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions .github/actions/AddComment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See LICENSE in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { OctoKit } from '../api/octokit'
import { getInput, getRequiredInput } from '../common/utils'
import { AddComment } from './AddComment'
import { Action } from '../common/Action'

class AddCommentAction extends Action {
id = 'AddComment';

async onTriggered(github: OctoKit) {
await new AddComment(
github,
getInput('createdAfter') || undefined,
+(getInput('afterDays') || 0),
getRequiredInput('labels'),
getInput('addComment') || '',
getInput('addLabels') || undefined,
getInput('removeLabels') || undefined,
getInput('setMilestoneId') || undefined,
getInput('milestoneName') || undefined,
getInput('milestoneId') || undefined,
getInput('ignoreLabels') || undefined,
getInput('ignoreMilestoneNames') || undefined,
getInput('ignoreMilestoneIds') || undefined,
+(getInput('minimumVotes') || 0),
+(getInput('maximumVotes') || 9999999),
getInput('involves') || undefined
).run();
}
}

new AddCommentAction().run(); // eslint-disable-line
2 changes: 1 addition & 1 deletion .github/actions/Locker/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ inputs:
milestoneId:
description: items with these milestones will be considered (id only, must match name)
labels:
description: items with these labels will not be considered. May be "*".
description: items with these labels will be considered. May be "*".
ignoreMilestoneNames:
description: items with these milestones will not be considered (names only, must match IDs). May be "*".
ignoreMilestoneIds:
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/Reopener/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ inputs:
milestoneId:
description: items with these milestones will be considered (id only, must match name)
labels:
description: items with these labels will not be considered. May be "*".
description: items with these labels will be considered. May be "*".
ignoreMilestoneNames:
description: items with these milestones will not be considered (names only, must match IDs). May be "*".
ignoreMilestoneIds:
Expand Down
Loading

1 comment on commit 6324549

@dcmade01
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hello im new to coding how do you go about this i need a repositor can you follow back

Please sign in to comment.