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 31, 2020
1 parent 17e8d18 commit ff35d26
Show file tree
Hide file tree
Showing 13 changed files with 614 additions and 6 deletions.
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("### Define CODEOWNERS")
}
handleFail()
}
Expand Down
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();
42 changes: 42 additions & 0 deletions src/dev/code_coverage/ingest_coverage/__tests__/maybe.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { fromNullable } from '../maybe';

describe(`maybe algebraic datatype functions`, () => {
const pluck = (x) => (obj) => obj[x];
const attempt = (obj) => fromNullable(obj).map(pluck('detail'));
describe(`helpers`, () => {
it(`'fromNullable' should be a fn`, () => {
expect(typeof fromNullable).toBe('function');
});
});
describe(`'fromNullable`, () => {
it(`should continue processing if a truthy is calculated`, () => {
expect(attempt({ detail: 'x' }).value()).toBe('x');
});
it(`should drop processing if a falsey is calculated`, () => {
const obj = {
a: 'abc',
};

expect(fromNullable(obj.b).inspect()).toBe('[Nothing]');
});
});
});
4 changes: 4 additions & 0 deletions src/dev/code_coverage/ingest_coverage/either.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
/* eslint new-cap: 0 */
/* eslint no-unused-vars: 0 */

import { pretty } from './utils';

export const Right = (x) => ({
chain: (f) => f(x),
map: (f) => Right(f(x)),
fold: (leftFn, rightFn) => rightFn(x),
inspect: () => `Right(${x})`,
inspectPretty: () => `Right(${pretty(x)})`,
});

Right.of = function of(x) {
Expand All @@ -40,6 +43,7 @@ export const Left = (x) => ({
map: (f) => Left(x),
fold: (leftFn, rightFn) => leftFn(x),
inspect: () => `Left(${x})`,
inspectPretty: () => `Left(${pretty(x)})`,
});

Left.of = function of(x) {
Expand Down
9 changes: 6 additions & 3 deletions src/dev/code_coverage/ingest_coverage/maybe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
/* eslint new-cap: 0 */
/* eslint no-unused-vars: 0 */

import { pretty } from './utils';

/**
* Just monad used for valid values
*/
Expand All @@ -29,6 +31,7 @@ export function Just(x) {
map: (f) => Maybe.of(f(x)),
isJust: () => true,
inspect: () => `Just(${x})`,
inspectPretty: () => `Just(${pretty(x)})`,
};
}
Just.of = function of(x) {
Expand All @@ -48,6 +51,7 @@ export function Maybe(x) {
chain: (f) => f(x),
map: (f) => Maybe(f(x)),
inspect: () => `Maybe(${x})`,
inspectPretty: () => `Maybe(${pretty(x)})`,
nothing: () => Nothing(),
isNothing: () => false,
isJust: () => false,
Expand All @@ -60,9 +64,8 @@ Maybe.of = function of(x) {
export function maybe(x) {
return Maybe.of(x);
}
export function fromNullable(x) {
return x !== null && x !== undefined && x !== false && x !== 'undefined' ? just(x) : nothing();
}
export const fromNullable = (x) =>
x !== null && x !== undefined && x !== false && x !== 'undefined' ? just(x) : nothing();

/**
* Nothing wraps undefined or null values and prevents errors
Expand Down
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);
});
});
});
37 changes: 37 additions & 0 deletions src/dev/code_owners/flush.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 } from 'fs';

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) => (log) => (ownersMap) => {
log.info(`\n### Flushing to codeOwnersPath: \n\t${codeOwnersPath}`);
const file = createWriteStream(codeOwnersPath);

file.write(preamble);

ownersMap.forEach(({ owners /* review, teams */ }, key) => {
file.write(`${key} ${owners.join(' ')}\n`);
});

file.end();
};
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)));
}
37 changes: 37 additions & 0 deletions src/dev/code_owners/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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 { resolve } from 'path';
import { run } from '@kbn/dev-utils';
import { parseSourceOfTruth } from './parse';
import { sourceOfTruth as sot } from './owners_source_of_truth';
import { flush } from './flush';

const ROOT = resolve(__dirname, '../../..');
const resolveFromRoot = resolve.bind(null, ROOT);
const codeownersPath = resolveFromRoot('.github/draft_CODEOWNERS');
const description = `
Create .github/CODEOWNERS file from authoritative source
`;

export const defineCodeOwners = () => {
run(({ log }) => flush(codeownersPath)(log)(parseSourceOfTruth(log)(sot)), { description });
};
Loading

0 comments on commit ff35d26

Please sign in to comment.