Skip to content

Commit

Permalink
[QA] Canonical Code Coverage Teams and CODEOWNERS Assignment
Browse files Browse the repository at this point in the history
Add the first draft of the TEAMS assignments,
including defaults for code coverage and teams.
After this PR, we will add a CI check to verify
all defined paths have CODEOWNERship,
and possibly code coverage teams.

Resovles #72692
  • Loading branch information
wayneseymour committed Jul 29, 2020
1 parent 0756dd3 commit 64094ad
Show file tree
Hide file tree
Showing 5 changed files with 569 additions and 0 deletions.
21 changes: 21 additions & 0 deletions scripts/canonical_codeowners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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.
*/

require('../src/setup_node_env');
require('../src/dev/code_owners').defineCodeOwners();
34 changes: 34 additions & 0 deletions src/dev/code_owners/__tests__/code_owners.test.js
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.
*/

import expect from '@kbn/expect';
import { hasPath } from '../';

describe(`Code Owners`, () => {
describe(`hasPath predicate fn`, () => {
const iterable = new Map();
iterable.set('a', 'b');
it(`should return true if the iterable has the path`, () => {
expect(hasPath('a')(iterable)).to.be(true);
});
it(`should return false if the iterable does not have the path`, () => {
expect(hasPath('b')(iterable)).to.be(false);
});
});
});
47 changes: 47 additions & 0 deletions src/dev/code_owners/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { pretty } from '../code_coverage/ingest_coverage/utils';

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

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

export function hasPath(path) {
return (iterable) => !!iterable.has(path);
}

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

function dropPrefix(prefix) {
return (x) => x.replace(prefix, '');
}
export function hasOverrides(xs) {
return !!Array.isArray(xs[0]);
}

export function printMap(map) {
map.forEach((value, key) => console.log(key + ' -> ' + pretty(value)));
}
54 changes: 54 additions & 0 deletions src/dev/code_owners/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 { sourceOfTruth as sot } from './owners_source_of_truth';
import { left, right } from '../code_coverage/ingest_coverage/either';
import { printMap, teamName, hasPath } from './helpers';

export const defineCodeOwners = () => {
const init = new Map();

const owners = sot.reduce((acc, { title, githubHandle, pathPatterns }) => {
pathPatterns.forEach((path) => {
const handle = `@${githubHandle}`;
const team = teamName(githubHandle);

const whether = hasPath(path)(acc) ? right(acc) : left(acc);

const alreadyHas = (path) => (accObj) => {
const { owners: currOwners, teams: currTeams } = accObj.get(path);

accObj.set(path, {
owners: currOwners.concat(handle),
teams: currTeams.concat(team),
title,
});
};

const orNot = (path) => (accObj) =>
accObj.set(path, { owners: [handle], teams: [team], title });

whether.fold(orNot(path), alreadyHas(path));
});

return acc;
}, init);

printMap(owners);
};
Loading

0 comments on commit 64094ad

Please sign in to comment.