Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QA] Canonical CODEOWNERS 2nd Draft #74310

Closed
wants to merge 6 commits into from
Closed
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
7 changes: 4 additions & 3 deletions .ci/Jenkinsfile_coverage
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ kibanaPipeline(timeoutMinutes: 240) {
]) {
workers.base(name: 'coverage-worker', size: 'l', ramDisk: false, bootstrapped: false) {
catchError {
kibanaCoverage.runTests()
kibanaTeamAssign.load('team_assignment', "### Upload Team Assignment JSON")
handleIngestion(TIME_STAMP)
// kibanaCoverage.runTests()
// kibanaTeamAssign.load('team_assignment', "### Upload Team Assignment JSON")
// handleIngestion(TIME_STAMP)
kibanaTeamAssign.defineCodeOwners('.github/CODEOWNERS', "### Define CODEOWNERS")
}
handleFail()
}
Expand Down
48 changes: 48 additions & 0 deletions packages/kbn-dev-utils/src/code_owners/flush.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { createWriteStream, PathLike, WriteStream } from 'fs';
import { ToolingLog } from '../tooling_log';

const preamble = `# GitHub CODEOWNERS definition
# Identify which groups will be pinged by changes to different parts of the codebase.
# For more info, see https://help.github.com/articles/about-codeowners/\n\n`;

export const flush = (codeOwnersPath: PathLike) => (log: ToolingLog) => (ownersMap: any) => {
const file: WriteStream = createWriteStream(codeOwnersPath);
file.write(preamble);
const recordToFile = record(file)(log);

interface OwnerRecord {
owners: [];
}
ownersMap.forEach(({ owners }: OwnerRecord, key: string) => {
const flat = owners.join(' ');
const item = `${key} ${flat}\n`;
if (owners.length) recordToFile(item);
});

file.end();

log.info(`\n### Data written to codeOwnersPath: \n\t${codeOwnersPath}`);
};

function record(file: WriteStream) {
return (log: ToolingLog) => (item: string) => file.write(item) && log.debug(item);
}
34 changes: 34 additions & 0 deletions packages/kbn-dev-utils/src/code_owners/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export function teamName(githubHandle: string) {
const prefix: RegExp = /elastic\//;
const dropElastic = dropPrefix(prefix);
const prefixedWithES = prefixed(prefix);

return prefixedWithES(githubHandle) ? dropElastic(githubHandle) : githubHandle;
}

function prefixed(prefix: RegExp) {
return (x: string) => prefix.test(x);
}

function dropPrefix(prefix: RegExp) {
return (x: string) => x.replace(prefix, '');
}
40 changes: 40 additions & 0 deletions packages/kbn-dev-utils/src/code_owners/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { PathLike } from 'fs';
import { run } from '../run';
import { parseSourceOfTruth } from './parse';
import { sourceOfTruth as sot } from './owners_source_of_truth';
import { flush } from './flush';
import { ToolingLog } from '../tooling_log';

const codeownersPath = process.env.CODEOWNERS_PATH;
const description = `

Create .github/CODEOWNERS file from authoritative source

`;

export const buildPathsMap = () => parseSourceOfTruth(sot as []);

export const defineCodeOwners = () => {
run(({ log }) => flush(codeownersPath as PathLike)(log as ToolingLog)(buildPathsMap()), {
description,
});
};
Loading