Skip to content

Commit d155922

Browse files
committed
testsIssueComment: prepare for additional body contents
In the next commit, we will start to test more interesting commands than `/hi`, commands that will need more/other information to be passed in the body. Let's add an easy way to do that. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b557b82 commit d155922

1 file changed

Lines changed: 24 additions & 6 deletions

File tree

__tests__/index.test.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,30 @@ const makeContext = (body, headers) => {
8282
}
8383
}
8484

85-
const testIssueComment = (comment, fn) => {
86-
const context = makeContext({
85+
function extend (a, ...list) {
86+
for (const b of list) {
87+
for (const key of Object.keys(b)) {
88+
if (Array.isArray(key[a])) a[key].push(...(Array.isArray(b[key]) ? b[key] : [ b[key] ]))
89+
if (a[key] !== null && a[key] instanceof Object) extend(a[key], b[key])
90+
else a[key] = b[key]
91+
}
92+
}
93+
return a
94+
}
95+
96+
const testIssueComment = (comment, bodyExtra_, fn) => {
97+
if (!fn) {
98+
fn = bodyExtra_
99+
bodyExtra_= undefined
100+
}
101+
const repo = bodyExtra_?.repository?.name || 'git'
102+
const number = bodyExtra_?.issue?.number || 0
103+
const pullOrIssues = bodyExtra_?.issue?.pull_request ? 'pull' : 'issues'
104+
const context = makeContext(extend({
87105
action: 'created',
88106
comment: {
89107
body: comment,
90-
html_url: 'https://github.com/git-for-windows/git/issues/0',
108+
html_url: `https://github.com/git-for-windows/${repo}/${pullOrIssues}/${number}`,
91109
id: 0,
92110
user: {
93111
login: 'statler and waldorf'
@@ -97,15 +115,15 @@ const testIssueComment = (comment, fn) => {
97115
id: 123
98116
},
99117
issue: {
100-
number: 0
118+
number
101119
},
102120
repository: {
103-
name: 'git',
121+
name: repo,
104122
owner: {
105123
login: 'git-for-windows'
106124
}
107125
}
108-
}, {
126+
}, bodyExtra_ ? bodyExtra_ : {}), {
109127
'x-github-event': 'issue_comment'
110128
})
111129

0 commit comments

Comments
 (0)