Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions __tests__/integration/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,18 @@ function createMockOctokit() {
const issuesUpdateComment = jest.fn().mockResolvedValue({});
const issuesDeleteComment = jest.fn().mockResolvedValue({});

// Production now uses `.request()` for `repos.getBranch` too (PR fixing
// Bug #16 — `app.js:268` was on `context.octokit.repos.getBranch` which
// shares the PR-#22 failure mode). Route GET branches into a namespaced
// mock so existing `octokit.repos.getBranch.mockX` test calls still work.
const reposGetBranch = jest.fn().mockResolvedValue({ data: { name: 'main' } });

const routeDispatch = {
'POST /repos/{owner}/{repo}/issues': issuesCreate,
'POST /repos/{owner}/{repo}/issues/{issue_number}/comments': issuesCreateComment,
'PATCH /repos/{owner}/{repo}/issues/comments/{comment_id}': issuesUpdateComment,
'DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}': issuesDeleteComment
'DELETE /repos/{owner}/{repo}/issues/comments/{comment_id}': issuesDeleteComment,
'GET /repos/{owner}/{repo}/branches/{branch}': reposGetBranch
};

const request = jest.fn((route, params) => {
Expand All @@ -169,7 +176,7 @@ function createMockOctokit() {
deleteComment: issuesDeleteComment
},
repos: {
getBranch: jest.fn().mockResolvedValue({ data: { name: 'main' } })
getBranch: reposGetBranch
},
request
};
Expand Down
12 changes: 7 additions & 5 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,13 @@ function registerApp(app, options = {}) {

for (let attempt = 1; attempt <= 3; attempt++) {
try {
await context.octokit.repos.getBranch({
owner,
repo: repoName,
branch: defaultBranch
});
// Use .request() form rather than .repos.getBranch — Probot v14's
// `context.octokit.repos` namespace is unreliable on this event
// type (same root cause as PRs #22 / #29 / #30 for `.issues.X`).
await context.octokit.request(
'GET /repos/{owner}/{repo}/branches/{branch}',
{ owner, repo: repoName, branch: defaultBranch }
);
branchReady = true;
break;
} catch (err) {
Expand Down
Loading