Skip to content

Commit 62e3406

Browse files
committed
feat: #32 orgs visible always
1 parent 0a119a0 commit 62e3406

File tree

5 files changed

+107
-5
lines changed

5 files changed

+107
-5
lines changed

dist/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80833,7 +80833,7 @@ async function main() {
8083380833
if (repositoryFilter.length > 0) {
8083480834
text = `_<${_constants_js__WEBPACK_IMPORTED_MODULE_4__/* .workflowUrl */ .pk}|Repository filter>: ${(0,_krauters_utils__WEBPACK_IMPORTED_MODULE_2__.formatStringList)(repositoryFilter)}_`;
8083580835
}
80836-
const orgs = [...new Set(dedupedPulls.map((pull) => pull.org))];
80836+
const orgs = [...new Set(results.map((result) => result.org))];
8083780837
blocks = [...(0,_utils_slack_blocks_js__WEBPACK_IMPORTED_MODULE_7__/* .getFirstBlocks */ .nh)(orgs, header, text), ...blocks];
8083880838
blocks = [
8083980839
...blocks,
@@ -90365,7 +90365,7 @@ module.exports = {"version":"3.17.0"};
9036590365
/***/ 8330:
9036690366
/***/ ((module) => {
9036790367

90368-
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.0.1","TB":"https://buymeacoffee.com/coltenkrauter"}');
90368+
module.exports = /*#__PURE__*/JSON.parse('{"UU":"@krauters/github-notifier","rE":"1.1.0","TB":"https://buymeacoffee.com/coltenkrauter"}');
9036990369

9037090370
/***/ })
9037190371

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@krauters/github-notifier",
33
"description": "GitHub Notifier by Krauters – Post Open Pull Requests to Slack",
4-
"version": "1.0.1",
4+
"version": "1.1.0",
55
"author": "Colten Krauter <coltenkrauter>",
66
"type": "module",
77
"homepage": "https://buymeacoffee.com/coltenkrauter",

src/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function main(): Promise<void> {
116116
text = `_<${workflowUrl}|Repository filter>: ${formatStringList(repositoryFilter)}_`
117117
}
118118

119-
const orgs = [...new Set(dedupedPulls.map((pull) => pull.org))]
119+
const orgs = [...new Set(results.map((result) => result.org))]
120120
blocks = [...getFirstBlocks(orgs, header, text), ...blocks]
121121

122122
blocks = [

test/app.test.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
/* eslint-disable @typescript-eslint/no-explicit-any */
3+
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'
4+
5+
// Mock all required modules
6+
jest.mock('@actions/core')
7+
jest.mock('@actions/github', () => ({
8+
context: {
9+
payload: { repository: { name: 'test-repo' } },
10+
repo: { owner: 'test-owner' },
11+
},
12+
getOctokit: jest.fn(),
13+
}))
14+
15+
// Mock the main modules we'll need
16+
const mockGetFirstBlocks = jest.fn()
17+
jest.mock('../src/utils/slack/blocks.js', () => ({
18+
getFirstBlocks: mockGetFirstBlocks,
19+
getLastBlocks: jest.fn(() => []),
20+
getPullBlocks: jest.fn(() => Promise.resolve([])),
21+
}))
22+
23+
const mockSlackPostMessage = jest.fn()
24+
jest.mock('../src/utils/slack/slack-client.js', () => ({
25+
SlackClient: jest.fn(() => ({
26+
enforceAppNamePattern: jest.fn(),
27+
postMessage: mockSlackPostMessage,
28+
})),
29+
}))
30+
31+
jest.mock('../src/utils/github/github-client.js', () => {
32+
const mockGetOrg = jest.fn()
33+
mockGetOrg.mockImplementation(() => Promise.resolve({ name: 'test-org' }))
34+
35+
return {
36+
GitHubClient: jest.fn(() => ({
37+
getOrg: mockGetOrg,
38+
getPulls: jest.fn(() => Promise.resolve([])),
39+
getRepositories: jest.fn(() => Promise.resolve([])),
40+
})),
41+
}
42+
})
43+
44+
jest.mock('../src/utils/test-data.js')
45+
jest.mock('../src/input-parser.js', () => ({
46+
parseInputs: jest.fn(() => ({
47+
githubConfig: {
48+
options: {},
49+
tokens: ['fake-token1', 'fake-token2'],
50+
},
51+
repositoryFilter: [],
52+
slackConfig: { channels: [], token: 'fake-token' },
53+
withArchived: false,
54+
withDrafts: false,
55+
withPublic: false,
56+
withTestData: false,
57+
withUserMentions: false,
58+
})),
59+
}))
60+
61+
describe('Organization links in Slack notifications', () => {
62+
beforeEach(() => {
63+
jest.resetAllMocks()
64+
jest.spyOn(console, 'log').mockImplementation(jest.fn())
65+
jest.spyOn(console, 'error').mockImplementation(jest.fn())
66+
})
67+
68+
afterEach(() => {
69+
jest.restoreAllMocks()
70+
})
71+
72+
it('passes org names to getFirstBlocks from results array, not dedupedPulls', () => {
73+
// We test this logic:
74+
// const orgs = [...new Set(results.map((result) => result.org))]
75+
// blocks = [...getFirstBlocks(orgs, header, text), ...blocks]
76+
77+
jest.isolateModules(() => {
78+
// Create spies to verify the behavior
79+
const orgSpy = jest.fn()
80+
mockGetFirstBlocks.mockImplementation((orgs) => {
81+
orgSpy(orgs)
82+
83+
return []
84+
})
85+
86+
// This test doesn't actually run the code in app.ts, but verifies
87+
// that with the fix in place, orgs would be obtained from results
88+
// rather than dedupedPulls when there are no PRs
89+
const results = [{ org: 'org1' }, { org: 'org2' }]
90+
91+
const dedupedPulls: any[] = []
92+
93+
// Simulate the fixed code behavior
94+
const orgs = [...new Set(results.map((result) => result.org))]
95+
expect(orgs).toEqual(['org1', 'org2'])
96+
97+
// Verify that the old behavior would result in empty orgs
98+
const oldOrgs = [...new Set(dedupedPulls.map((pull) => (pull as { org: string }).org))]
99+
expect(oldOrgs).toEqual([])
100+
})
101+
})
102+
})

0 commit comments

Comments
 (0)