Skip to content

Commit

Permalink
feat(results): include repository owner in results filenames
Browse files Browse the repository at this point in the history
- Adds support for duplicate repository names, e.g. when linting forks
  • Loading branch information
AriPerkkio committed Nov 4, 2020
1 parent e633d62 commit 21e45a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/file-client/results-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ export function writeResults(results: LintMessage[], repository: string): void {
if (!results.length) {
return;
}
const [, repositoryName] = repository.split('/');

// Construct result file name, e.g. mui-org_material-ui.md
const repositoryOwnerAndName = repository.split('/').join('_');
const fileName = `${repositoryOwnerAndName}${RESULT_EXTENSION}`;

const formattedResults = formatResults(results, repository);
RESULTS.push(formattedResults);

if (!config.CI) {
fs.writeFileSync(
`${RESULTS_LOCATION}/${repositoryName}${RESULT_EXTENSION}`,
`${RESULTS_LOCATION}/${fileName}`,
formattedResults,
'utf8'
);
Expand Down
8 changes: 5 additions & 3 deletions test/integration/integration.cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
} from '../utils';
import { RESULTS_LOCATION, CACHE_LOCATION } from '@file-client';

const RESULTS_FILE = `${INTEGRATION_REPO_OWNER}_${INTEGRATION_REPO_NAME}.md`;

describe('CLI', () => {
beforeEach(async () => {
await runProductionBuild();
Expand All @@ -17,12 +19,12 @@ describe('CLI', () => {
const files = fs.readdirSync(RESULTS_LOCATION);

expect(files).toHaveLength(1);
expect(files[0]).toMatch(`${INTEGRATION_REPO_NAME}.md`);
expect(files[0]).toMatch(RESULTS_FILE);
});

test("validates repository's files", () => {
const results = fs.readFileSync(
`${RESULTS_LOCATION}/${INTEGRATION_REPO_NAME}.md`,
`${RESULTS_LOCATION}/${RESULTS_FILE}`,
'utf8'
);

Expand Down Expand Up @@ -92,7 +94,7 @@ describe('CLI', () => {

test('excludes files matching exclude pattern', () => {
const results = fs.readFileSync(
`${RESULTS_LOCATION}/${INTEGRATION_REPO_NAME}.md`,
`${RESULTS_LOCATION}/${RESULTS_FILE}`,
'utf8'
);

Expand Down

0 comments on commit 21e45a3

Please sign in to comment.