message: indexing of github team members
diff: @@ -60,7 +60,7 @@ class GitHubUpdater {
  type: "content-types",
  id: "users",
  "relationships": {
  - "data-source": this.dataSourceId,
  + "data-source": { data: { type: "data-sources", id: this.dataSourceId } },
  "fields": {
  "data": [
  {
  @@ -83,10 +83,41 @@ class GitHubUpdater {
  }
  async updateContent(meta, hints, ops) {
  + let users = new Map();
  + for (let teamId of this.teamIds) {
  + for (let member of await this._getTeamMembers(teamId)) {
  + let record = users.get(member.id);
  + if (!record) {
  + let user = await this._getUser(member.login);
  + record = {
  + id: user.id,
  + type: 'users',
  + attributes: {
  + 'full-name': user.name,
  + email: user.email,
  + avatar: user.avatar_url
  + },
  + relationships: {
  + groups: {
  + data: []
  + }
  + }
  + };
  + users.set(record.id, record);
  + }
  + record.relationships.groups.data.push({ type: 'groups', id: teamId });
  + }
  + }
  + for (let user of users.values()) {
  + await ops.save('users', user.id, user);
  + }
  + }
  +
  + async _getTeamMembers(teamId) {
  let options = {
  hostname: 'api.github.com',
  port: 443,
  - path: '/user',
  + path: `/teams/${teamId}/members`,
  method: 'GET',
  headers: {
  'Accept': 'application/json',
  @@ -94,9 +125,25 @@ class GitHubUpdater {
  Authorization: `token ${this.ownToken}`
  }
  };
  -
  let response = await request(options);
  + return response.body;
  + }
  + async _getUser(login) {
  + let options = {
  + hostname: 'api.github.com',
  + port: 443,
  + path: `/users/${login}`,
  + method: 'GET',
  + headers: {
  + 'Accept': 'application/json',
  + 'User-Agent': '@cardstack/github-auth',
  + Authorization: `token ${this.ownToken}`
  + }
  + };
  + let response = await request(options);
  + return response.body;
  }
  +
  }
  