mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-19 14:35:50 +00:00
✨ minimize comment
This commit is contained in:
parent
3c38ed8cd4
commit
4bc21b7b93
5 changed files with 65 additions and 6 deletions
|
|
@ -6,7 +6,8 @@ import {
|
||||||
deleteComment,
|
deleteComment,
|
||||||
findPreviousComment,
|
findPreviousComment,
|
||||||
getBodyOf,
|
getBodyOf,
|
||||||
updateComment
|
updateComment,
|
||||||
|
minimizeComment
|
||||||
} from "../src/comment"
|
} from "../src/comment"
|
||||||
|
|
||||||
jest.mock("@actions/core", () => ({
|
jest.mock("@actions/core", () => ({
|
||||||
|
|
@ -198,6 +199,19 @@ it("deleteComment", async () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("minimizeComment", async () => {
|
||||||
|
const octokit = getOctokit("github-token")
|
||||||
|
|
||||||
|
jest.spyOn(octokit, "graphql").mockReturnValue(undefined as any)
|
||||||
|
expect(await minimizeComment(octokit, "456", "OUTDATED")).toBeUndefined()
|
||||||
|
expect(octokit.graphql).toBeCalledWith(expect.any(String), {
|
||||||
|
input: {
|
||||||
|
subjectId: "456",
|
||||||
|
classifier: "OUTDATED"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe("getBodyOf", () => {
|
describe("getBodyOf", () => {
|
||||||
const nullPrevious = {}
|
const nullPrevious = {}
|
||||||
const simplePrevious = {
|
const simplePrevious = {
|
||||||
|
|
|
||||||
14
dist/index.js
generated
vendored
14
dist/index.js
generated
vendored
|
|
@ -35,7 +35,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
exports.getBodyOf = exports.minimizeComment = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||||
const core = __importStar(__nccwpck_require__(186));
|
const core = __importStar(__nccwpck_require__(186));
|
||||||
function headerComment(header) {
|
function headerComment(header) {
|
||||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||||
|
|
@ -137,6 +137,18 @@ function deleteComment(octokit, id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.deleteComment = deleteComment;
|
exports.deleteComment = deleteComment;
|
||||||
|
function minimizeComment(octokit, subjectId, classifier) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield octokit.graphql(`
|
||||||
|
mutation($input: MinimizeCommentInput!) {
|
||||||
|
minimizeComment(input: $input) {
|
||||||
|
clientMutationId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, { input: { subjectId, classifier } });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.minimizeComment = minimizeComment;
|
||||||
function getBodyOf(previous, append, hideDetails) {
|
function getBodyOf(previous, append, hideDetails) {
|
||||||
var _a;
|
var _a;
|
||||||
if (!append) {
|
if (!append) {
|
||||||
|
|
|
||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
14
lib/comment.js
generated
14
lib/comment.js
generated
|
|
@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.getBodyOf = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
exports.getBodyOf = exports.minimizeComment = exports.deleteComment = exports.createComment = exports.updateComment = exports.findPreviousComment = void 0;
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
function headerComment(header) {
|
function headerComment(header) {
|
||||||
return `<!-- Sticky Pull Request Comment${header} -->`;
|
return `<!-- Sticky Pull Request Comment${header} -->`;
|
||||||
|
|
@ -130,6 +130,18 @@ function deleteComment(octokit, id) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.deleteComment = deleteComment;
|
exports.deleteComment = deleteComment;
|
||||||
|
function minimizeComment(octokit, subjectId, classifier) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield octokit.graphql(`
|
||||||
|
mutation($input: MinimizeCommentInput!) {
|
||||||
|
minimizeComment(input: $input) {
|
||||||
|
clientMutationId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, { input: { subjectId, classifier } });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.minimizeComment = minimizeComment;
|
||||||
function getBodyOf(previous, append, hideDetails) {
|
function getBodyOf(previous, append, hideDetails) {
|
||||||
var _a;
|
var _a;
|
||||||
if (!append) {
|
if (!append) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import {IssueComment, Repository, User} from "@octokit/graphql-schema"
|
import {
|
||||||
|
IssueComment,
|
||||||
|
ReportedContentClassifiers,
|
||||||
|
Repository,
|
||||||
|
User
|
||||||
|
} from "@octokit/graphql-schema"
|
||||||
import {GitHub} from "@actions/github/lib/utils"
|
import {GitHub} from "@actions/github/lib/utils"
|
||||||
|
|
||||||
function headerComment(header: String): string {
|
function headerComment(header: String): string {
|
||||||
|
|
@ -14,7 +19,7 @@ export async function findPreviousComment(
|
||||||
},
|
},
|
||||||
number: number,
|
number: number,
|
||||||
header: string
|
header: string
|
||||||
): Promise<{body: string; id: string} | undefined> {
|
): Promise<IssueComment | undefined> {
|
||||||
let after = null
|
let after = null
|
||||||
let hasNextPage = true
|
let hasNextPage = true
|
||||||
const h = headerComment(header)
|
const h = headerComment(header)
|
||||||
|
|
@ -133,6 +138,22 @@ export async function deleteComment(
|
||||||
{id}
|
{id}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
export async function minimizeComment(
|
||||||
|
octokit: InstanceType<typeof GitHub>,
|
||||||
|
subjectId: string,
|
||||||
|
classifier: ReportedContentClassifiers
|
||||||
|
): Promise<void> {
|
||||||
|
await octokit.graphql(
|
||||||
|
`
|
||||||
|
mutation($input: MinimizeCommentInput!) {
|
||||||
|
minimizeComment(input: $input) {
|
||||||
|
clientMutationId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
{input: {subjectId, classifier}}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function getBodyOf(
|
export function getBodyOf(
|
||||||
previous: {body?: string},
|
previous: {body?: string},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue