mirror of
https://github.com/marocchino/sticky-pull-request-comment.git
synced 2025-12-19 06:25:50 +00:00
build: new deps & rest fix
This commit is contained in:
parent
78ec57a610
commit
a8d139a171
5 changed files with 278 additions and 108 deletions
|
|
@ -49,6 +49,7 @@ it('findPreviousComment', async () => {
|
|||
}
|
||||
]
|
||||
const octokit: any = {
|
||||
rest: {
|
||||
issues: {
|
||||
listComments: jest.fn(() =>
|
||||
Promise.resolve({
|
||||
|
|
@ -62,6 +63,7 @@ it('findPreviousComment', async () => {
|
|||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
expect(await findPreviousComment(octokit, repo, 123, '')).toBe(comment)
|
||||
expect(await findPreviousComment(octokit, repo, 123, 'TypeA')).toBe(
|
||||
|
|
@ -70,7 +72,7 @@ it('findPreviousComment', async () => {
|
|||
expect(await findPreviousComment(octokit, repo, 123, 'LegacyComment')).toBe(
|
||||
headerFirstComment
|
||||
)
|
||||
expect(octokit.issues.listComments).toBeCalledWith({
|
||||
expect(octokit.rest.issues.listComments).toBeCalledWith({
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
issue_number: 123
|
||||
|
|
@ -82,17 +84,19 @@ describe('updateComment', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
octokit = {
|
||||
rest: {
|
||||
issues: {
|
||||
updateComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('with comment body', async () => {
|
||||
expect(
|
||||
await updateComment(octokit, repo, 456, 'hello there', '')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
expect(octokit.rest.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
|
|
@ -101,7 +105,7 @@ describe('updateComment', () => {
|
|||
expect(
|
||||
await updateComment(octokit, repo, 456, 'hello there', 'TypeA')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
expect(octokit.rest.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
|
|
@ -117,7 +121,7 @@ describe('updateComment', () => {
|
|||
'hello there\n<!-- Sticky Pull Request CommentTypeA -->'
|
||||
)
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).toBeCalledWith({
|
||||
expect(octokit.rest.issues.updateComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
|
|
@ -125,9 +129,9 @@ describe('updateComment', () => {
|
|||
})
|
||||
})
|
||||
|
||||
it('without comment body and previousbody', async () => {
|
||||
it('without comment body and previous body', async () => {
|
||||
expect(await updateComment(octokit, repo, 456, '', '')).toBeUndefined()
|
||||
expect(octokit.issues.updateComment).not.toBeCalled()
|
||||
expect(octokit.rest.issues.updateComment).not.toBeCalled()
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank')
|
||||
})
|
||||
})
|
||||
|
|
@ -137,17 +141,19 @@ describe('createComment', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
octokit = {
|
||||
rest: {
|
||||
issues: {
|
||||
createComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
it('with comment body or previousBody', async () => {
|
||||
expect(
|
||||
await createComment(octokit, repo, 456, 'hello there', '')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
|
|
@ -156,7 +162,7 @@ describe('createComment', () => {
|
|||
expect(
|
||||
await createComment(octokit, repo, 456, 'hello there', 'TypeA')
|
||||
).toBeUndefined()
|
||||
expect(octokit.issues.createComment).toBeCalledWith({
|
||||
expect(octokit.rest.issues.createComment).toBeCalledWith({
|
||||
issue_number: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment',
|
||||
|
|
@ -165,19 +171,21 @@ describe('createComment', () => {
|
|||
})
|
||||
it('without comment body and previousBody', async () => {
|
||||
expect(await createComment(octokit, repo, 456, '', '')).toBeUndefined()
|
||||
expect(octokit.issues.createComment).not.toBeCalled()
|
||||
expect(octokit.rest.issues.createComment).not.toBeCalled()
|
||||
expect(core.warning).toBeCalledWith('Comment body cannot be blank')
|
||||
})
|
||||
})
|
||||
|
||||
it('deleteComment', async () => {
|
||||
const octokit: any = {
|
||||
rest: {
|
||||
issues: {
|
||||
deleteComment: jest.fn(() => Promise.resolve())
|
||||
}
|
||||
}
|
||||
}
|
||||
expect(await deleteComment(octokit, repo, 456)).toBeUndefined()
|
||||
expect(octokit.issues.deleteComment).toBeCalledWith({
|
||||
expect(octokit.rest.issues.deleteComment).toBeCalledWith({
|
||||
comment_id: 456,
|
||||
owner: 'marocchino',
|
||||
repo: 'sticky-pull-request-comment'
|
||||
|
|
|
|||
299
dist/index.js
generated
vendored
299
dist/index.js
generated
vendored
File diff suppressed because one or more lines are too long
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
9
dist/licenses.txt
generated
vendored
9
dist/licenses.txt
generated
vendored
|
|
@ -12,6 +12,15 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||
|
||||
@actions/github
|
||||
MIT
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright 2019 GitHub
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
@actions/http-client
|
||||
MIT
|
||||
|
|
|
|||
8
lib/comment.js
generated
8
lib/comment.js
generated
|
|
@ -35,7 +35,7 @@ function headerComment(header) {
|
|||
}
|
||||
function findPreviousComment(octokit, repo, issue_number, header) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const { data: comments } = yield octokit.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
|
||||
const { data: comments } = yield octokit.rest.issues.listComments(Object.assign(Object.assign({}, repo), { issue_number }));
|
||||
const h = headerComment(header);
|
||||
return comments.find(comment => { var _a; return (_a = comment.body) === null || _a === void 0 ? void 0 : _a.includes(h); });
|
||||
});
|
||||
|
|
@ -45,7 +45,7 @@ function updateComment(octokit, repo, comment_id, body, header, previousBody) {
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!body && !previousBody)
|
||||
return core.warning('Comment body cannot be blank');
|
||||
yield octokit.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody
|
||||
yield octokit.rest.issues.updateComment(Object.assign(Object.assign({}, repo), { comment_id, body: previousBody
|
||||
? `${previousBody}\n${body}`
|
||||
: `${body}\n${headerComment(header)}` }));
|
||||
});
|
||||
|
|
@ -55,7 +55,7 @@ function createComment(octokit, repo, issue_number, body, header, previousBody)
|
|||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!body && !previousBody)
|
||||
return core.warning('Comment body cannot be blank');
|
||||
yield octokit.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody
|
||||
yield octokit.rest.issues.createComment(Object.assign(Object.assign({}, repo), { issue_number, body: previousBody
|
||||
? `${previousBody}\n${body}`
|
||||
: `${body}\n${headerComment(header)}` }));
|
||||
});
|
||||
|
|
@ -63,7 +63,7 @@ function createComment(octokit, repo, issue_number, body, header, previousBody)
|
|||
exports.createComment = createComment;
|
||||
function deleteComment(octokit, repo, comment_id) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield octokit.issues.deleteComment(Object.assign(Object.assign({}, repo), { comment_id }));
|
||||
yield octokit.rest.issues.deleteComment(Object.assign(Object.assign({}, repo), { comment_id }));
|
||||
});
|
||||
}
|
||||
exports.deleteComment = deleteComment;
|
||||
|
|
|
|||
Loading…
Reference in a new issue