Skip to content

Commit b0c8f88

Browse files
authored
Merge pull request #240 from mschoettle/org-members
Ensure assignees are members of the organization
2 parents 9b228d0 + 7fa16a3 commit b0c8f88

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/githubHelper.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class GithubHelper {
7878
useIssuesForAllMergeRequests: boolean;
7979
milestoneMap?: Map<number, SimpleMilestone>;
8080
users: Set<string>;
81+
members: Set<string>;
8182

8283
constructor(
8384
githubApi: GitHubApi,
@@ -99,6 +100,19 @@ export class GithubHelper {
99100
this.delayInMs = 2000;
100101
this.useIssuesForAllMergeRequests = useIssuesForAllMergeRequests;
101102
this.users = new Set<string>();
103+
104+
this.members = new Set<string>();
105+
106+
// TODO: won't work if ownerIsOrg is false
107+
githubApi.orgs.listMembers( {
108+
org: this.githubOwner,
109+
}).then(members => {
110+
for (let member of members.data) {
111+
this.members.add(member.login);
112+
}
113+
}).catch(err => {
114+
console.error(`Failed to fetch organization members: ${err}`);
115+
});
102116
}
103117

104118
/*
@@ -381,9 +395,16 @@ export class GithubHelper {
381395
if (username === settings.github.username) {
382396
assignees.push(settings.github.username);
383397
} else if (settings.usermap && settings.usermap[username]) {
384-
assignees.push(settings.usermap[username]);
398+
let gitHubUsername = settings.usermap[username];
399+
if (this.members.has(gitHubUsername)) {
400+
assignees.push(gitHubUsername);
401+
}
402+
else {
403+
console.log(`Cannot assign assignee: User ${gitHubUsername} is not a member of ${this.githubOwner}`);
404+
}
385405
}
386406
}
407+
387408
return assignees;
388409
}
389410

@@ -1360,7 +1381,7 @@ export class GithubHelper {
13601381
return Promise.resolve();
13611382
}
13621383

1363-
// Use the Issues API; all pull requests are issues, and we're not modifying any pull request-sepecific fields. This
1384+
// Use the Issues API; all pull requests are issues, and we're not modifying any pull request-specific fields. This
13641385
// then works for merge requests that cannot be created and are migrated as issues.
13651386
return await this.githubApi.issues.update(props);
13661387
}

0 commit comments

Comments
 (0)