-
-
Save priscilawebdev/0d20eb221c26de1078a8cc5350fbaae5 to your computer and use it in GitHub Desktop.
React Testing Library - Slack Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { PassThrough as PassThroughStream } from 'stream'; | |
import { Octokit } from '@octokit/rest'; | |
import { Parse as TarParser, ReadEntry } from 'tar'; | |
const owner = 'getsentry'; | |
const repo = 'sentry'; | |
export async function getProgress() { | |
const octokit = new Octokit(); | |
const testContent = await octokit.repos.getContent({ | |
owner, | |
repo, | |
path: 'static', | |
}); | |
if (!Array.isArray(testContent.data)) { | |
throw new Error('Invalid directory'); | |
} | |
const app = testContent.data.find(({ name }) => name === 'app'); | |
if (!app) { | |
throw new Error('Invalid directory'); | |
} | |
// Download the archive | |
const response = await octokit.rest.repos.downloadTarballArchive({ | |
owner, | |
repo, | |
ref: app.sha, | |
}); | |
// @ts-expect-error https://github.com/octokit/types.ts/issues/211 | |
const archiveData = Buffer.from(response.data); | |
const testFiles: string[] = []; | |
const testFilesWithEnzymeImport: string[] = []; | |
await new Promise<void>((resolve) => { | |
const stream = new PassThroughStream(); | |
stream.end(archiveData); | |
const parser = new TarParser({ | |
strict: true, | |
filter: (currentPath: string) => { | |
return /\.spec.*?$/.test(currentPath); | |
}, | |
onentry: (entry: ReadEntry) => { | |
testFiles.push(entry.path); | |
entry | |
.on('data', (data) => { | |
const content = Buffer.from(data).toString('utf-8'); | |
if (content.includes('sentry-test/enzyme')) { | |
testFilesWithEnzymeImport.push(entry.path); | |
} | |
}) | |
.resume(); | |
}, | |
}); | |
stream.pipe(parser).on('end', resolve); | |
}); | |
return { | |
remainingFiles: testFilesWithEnzymeImport.length, | |
progress: | |
Math.round( | |
(1 - testFilesWithEnzymeImport.length / testFiles.length) * 10000 | |
) / 100, | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { bolt } from '@api/slack'; | |
import { wrapHandler } from '@utils/wrapHandler'; | |
import { getProgress } from './getProgress'; | |
export function reactTestingLibrary() { | |
bolt.event( | |
'app_mention', | |
wrapHandler('rtl', async ({ event, say, client }) => { | |
if (!event.text.includes('rtl')) { | |
return; | |
} | |
const message = await say({ | |
text: ':sentry-loading: fetching status ...', | |
blocks: [ | |
{ | |
type: 'context', | |
elements: [ | |
{ | |
type: 'mrkdwn', | |
text: ':sentry-loading: fetching status ...', | |
}, | |
], | |
}, | |
], | |
}); | |
const { remainingFiles, progress } = await getProgress(); | |
await client.chat.update({ | |
channel: String(message.channel), | |
ts: String(message.ts), | |
text: `RTL progress: ${progress}% completed, ${remainingFiles} files remaining`, | |
blocks: [ | |
{ | |
type: 'section', | |
text: { | |
type: 'mrkdwn', | |
text: `:rtl: progress: *${progress}%* completed, *${remainingFiles}* files remaining`, | |
}, | |
}, | |
], | |
}); | |
}) | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment