Skip to content

Commit

Permalink
Revert Use team keys for authors (#88) (#96)
Browse files Browse the repository at this point in the history
* Revert "Add one example to show the new feature"

This reverts commit 4bc5b46.

* Revert "Fix the stub to return in the expected format (#93)"

This reverts commit a39c70b.

* Revert "Use team keys for authors (#88)"

This reverts commit bf71b47.
  • Loading branch information
necojackarc authored May 24, 2023
1 parent fec2e6a commit 6aa3ce1
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 86 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ reviewers:
designer_b:
- lead_desinger # username
- desinger_a # username
team:engineering-managers:
- engineers
files:
# Keys are glob expressions.
Expand Down
21 changes: 0 additions & 21 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,6 @@ async function assign_reviewers(reviewers) {
});
}

// https://docs.github.com/en/rest/teams/members?apiVersion=2022-11-28#list-team-members
async function get_team_members(team) {
const context = get_context();
const octokit = get_octokit();

return octokit.teams.listMembersInOrg({
org: context.repo.org,
team_slug: team,
})?.data?.map((member) => member.login);
}

/* Private */

let context_cache;
Expand Down Expand Up @@ -169,5 +158,4 @@ module.exports = {
fetch_changed_files,
assign_reviewers,
clear_cache,
get_team_members,
};
9 changes: 0 additions & 9 deletions src/reviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const core = require('@actions/core');
const minimatch = require('minimatch');
const sample_size = require('lodash/sampleSize');
const github = require('./github'); // Don't destructure this object to stub with sinon in tests

function fetch_other_group_members({ author, config }) {
const DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -78,14 +77,6 @@ function identify_reviewers_by_author({ config, 'author': specified_author }) {
return true;
}

if (author.startsWith('team:')) {
const team = author.replace('team:', '');
const individuals_in_team = github.get_team_members(team);
if (individuals_in_team.includes(specified_author)) {
return true;
}
}

const individuals_in_author_setting = replace_groups_with_individuals({ reviewers: [ author ], config });

if (individuals_in_author_setting.includes(specified_author)) {
Expand Down
26 changes: 0 additions & 26 deletions test/github.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
fetch_changed_files,
assign_reviewers,
clear_cache,
get_team_members,
} = require('../src/github');

describe('github', function() {
Expand Down Expand Up @@ -156,29 +155,4 @@ describe('github', function() {
});
});
});

describe('get_team_members()', function() {
const spy = sinon.spy();
const octokit = {
teams: {
listMembersInOrg: spy,
},
};

beforeEach(function() {
github.getOctokit.resetBehavior();
github.getOctokit.returns(octokit);
});

it('gets team members', async function() {
const team = 'koopa-troop';
await get_team_members(team);

expect(spy.calledOnce).to.be.true;
expect(spy.lastCall.args[0]).to.deep.equal({
org: 'necojackarc',
team_slug: 'koopa-troop',
});
});
});
});
19 changes: 4 additions & 15 deletions test/reviewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const {
} = require('../src/reviewer');
const { expect } = require('chai');

const github = require('../src/github');
const sinon = require('sinon');

describe('reviewer', function() {
describe('fetch_other_group_members()', function() {

Expand Down Expand Up @@ -72,6 +69,7 @@ describe('reviewer', function() {
});

describe('identify_reviewers_by_changed_files()', function() {

const config = {
reviewers: {
groups: {
Expand Down Expand Up @@ -138,17 +136,13 @@ describe('reviewer', function() {
designers: [ 'mario', 'princess-peach', 'princess-daisy' ],
},
per_author: {
'engineers': [ 'engineers', 'dr-mario' ],
'designers': [ 'designers' ],
'yoshi': [ 'mario', 'luige' ],
'team:koopa-troop': [ 'mario' ],
engineers: [ 'engineers', 'dr-mario' ],
designers: [ 'designers' ],
yoshi: [ 'mario', 'luige' ],
},
},
};

const stub = sinon.stub(github, 'get_team_members');
stub.withArgs('koopa-troop').returns([ 'bowser', 'king-boo', 'goomboss' ]);

it('returns nothing when config does not have a "per-author" key', function() {
const author = 'THIS DOES NOT MATTER';
expect(identify_reviewers_by_author({ config: { reviewers: {} }, author })).to.deep.equal([]);
Expand All @@ -173,11 +167,6 @@ describe('reviewer', function() {
const author = 'mario';
expect(identify_reviewers_by_author({ config, author })).to.have.members([ 'dr-mario', 'luigi', 'wario', 'waluigi', 'princess-peach', 'princess-daisy' ]);
});

it('works when gh team slug used for auther', function() {
const author = 'bowser';
expect(identify_reviewers_by_author({ config, author })).to.have.members([ 'mario' ]);
});
});

describe('should_request_review()', function() {
Expand Down
1 change: 0 additions & 1 deletion test/stubs/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class ContextStub {
return {
owner: 'necojackarc',
repo: 'auto-request-review',
org: 'necojackarc',
};
}
}
Expand Down

0 comments on commit 6aa3ce1

Please sign in to comment.