Skip to content
Merged
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
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80833,7 +80833,7 @@ async function main() {
if (repositoryFilter.length > 0) {
text = `_<${_constants_js__WEBPACK_IMPORTED_MODULE_4__/* .workflowUrl */ .pk}|Repository filter>: ${(0,_krauters_utils__WEBPACK_IMPORTED_MODULE_2__.formatStringList)(repositoryFilter)}_`;
}
const orgs = [...new Set(dedupedPulls.map((pull) => pull.org))];
const orgs = [...new Set(results.map((result) => result.org))];
blocks = [...(0,_utils_slack_blocks_js__WEBPACK_IMPORTED_MODULE_7__/* .getFirstBlocks */ .nh)(orgs, header, text), ...blocks];
blocks = [
...blocks,
Expand Down Expand Up @@ -90365,7 +90365,7 @@ module.exports = {"version":"3.17.0"};
/***/ 8330:
/***/ ((module) => {

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

/***/ })

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@krauters/github-notifier",
"description": "GitHub Notifier by Krauters – Post Open Pull Requests to Slack",
"version": "1.0.1",
"version": "1.1.0",
"author": "Colten Krauter <coltenkrauter>",
"type": "module",
"homepage": "https://buymeacoffee.com/coltenkrauter",
Expand Down
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async function main(): Promise<void> {
text = `_<${workflowUrl}|Repository filter>: ${formatStringList(repositoryFilter)}_`
}

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

blocks = [
Expand Down
102 changes: 102 additions & 0 deletions test/app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* eslint-disable @typescript-eslint/naming-convention */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { afterEach, beforeEach, describe, expect, it, jest } from '@jest/globals'

// Mock all required modules
jest.mock('@actions/core')
jest.mock('@actions/github', () => ({
context: {
payload: { repository: { name: 'test-repo' } },
repo: { owner: 'test-owner' },
},
getOctokit: jest.fn(),
}))

// Mock the main modules we'll need
const mockGetFirstBlocks = jest.fn()
jest.mock('../src/utils/slack/blocks.js', () => ({
getFirstBlocks: mockGetFirstBlocks,
getLastBlocks: jest.fn(() => []),
getPullBlocks: jest.fn(() => Promise.resolve([])),
}))

const mockSlackPostMessage = jest.fn()
jest.mock('../src/utils/slack/slack-client.js', () => ({
SlackClient: jest.fn(() => ({
enforceAppNamePattern: jest.fn(),
postMessage: mockSlackPostMessage,
})),
}))

jest.mock('../src/utils/github/github-client.js', () => {
const mockGetOrg = jest.fn()
mockGetOrg.mockImplementation(() => Promise.resolve({ name: 'test-org' }))

return {
GitHubClient: jest.fn(() => ({
getOrg: mockGetOrg,
getPulls: jest.fn(() => Promise.resolve([])),
getRepositories: jest.fn(() => Promise.resolve([])),
})),
}
})

jest.mock('../src/utils/test-data.js')
jest.mock('../src/input-parser.js', () => ({
parseInputs: jest.fn(() => ({
githubConfig: {
options: {},
tokens: ['fake-token1', 'fake-token2'],
},
repositoryFilter: [],
slackConfig: { channels: [], token: 'fake-token' },
withArchived: false,
withDrafts: false,
withPublic: false,
withTestData: false,
withUserMentions: false,
})),
}))

describe('Organization links in Slack notifications', () => {
beforeEach(() => {
jest.resetAllMocks()
jest.spyOn(console, 'log').mockImplementation(jest.fn())
jest.spyOn(console, 'error').mockImplementation(jest.fn())
})

afterEach(() => {
jest.restoreAllMocks()
})

it('passes org names to getFirstBlocks from results array, not dedupedPulls', () => {
// We test this logic:
// const orgs = [...new Set(results.map((result) => result.org))]
// blocks = [...getFirstBlocks(orgs, header, text), ...blocks]

jest.isolateModules(() => {
// Create spies to verify the behavior
const orgSpy = jest.fn()
mockGetFirstBlocks.mockImplementation((orgs) => {
orgSpy(orgs)

return []
})

// This test doesn't actually run the code in app.ts, but verifies
// that with the fix in place, orgs would be obtained from results
// rather than dedupedPulls when there are no PRs
const results = [{ org: 'org1' }, { org: 'org2' }]

const dedupedPulls: any[] = []

// Simulate the fixed code behavior
const orgs = [...new Set(results.map((result) => result.org))]
expect(orgs).toEqual(['org1', 'org2'])

// Verify that the old behavior would result in empty orgs
const oldOrgs = [...new Set(dedupedPulls.map((pull) => (pull as { org: string }).org))]
expect(oldOrgs).toEqual([])
})
})
})
Loading