@lbdudc/linea-git 0.2.2 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -408,6 +408,28 @@ export class LocalProvider {
408
408
  members.set(member.username, member.accessLevel);
409
409
  return [...members].map(([username, accessLevel]) => ({ username, accessLevel }));
410
410
  }
411
+ async listAccess({ token, id }) {
412
+ return (await this.getMembers({ token, id })).map((member) => ({ ...member, source: 'direct' }));
413
+ }
414
+ async setAccess({ token, id, username, accessLevel }) {
415
+ await this.setMember({ token, id, username, accessLevel });
416
+ }
417
+ async removeAccess({ token, id, username }) {
418
+ await this.removeMember({ token, id, username });
419
+ }
420
+ /** The names this host has seen as owners and members (the accounts are the server's: it searches them itself). */
421
+ async searchUsers({ token, query }) {
422
+ await this.user(token);
423
+ const state = await this.store.read((current) => current);
424
+ const names = new Set();
425
+ for (const repository of state.repositories) {
426
+ names.add(repository.owner);
427
+ for (const member of repository.members)
428
+ names.add(member.username);
429
+ }
430
+ const needle = query.trim().toLowerCase();
431
+ return [...names].filter((name) => name.toLowerCase().includes(needle)).slice(0, 10).map((username) => ({ username, name: username, avatarUrl: null }));
432
+ }
411
433
  async getAccessLevel({ token, id, username }) {
412
434
  await this.user(token);
413
435
  const state = await this.store.read((current) => current);
@@ -799,6 +821,7 @@ export class LocalProvider {
799
821
  assignees: this.cleanList(assignees), labels: this.cleanList(labels), milestone: milestone?.trim() || null,
800
822
  createdAt: now, updatedAt: now, closedAt: null, comments: [], nextComment: 1
801
823
  };
824
+ issue.labelEvents = this.labelChanges([], issue.labels, user.username, now);
802
825
  repository.nextIssue = issue.number + 1;
803
826
  repository.issues = [...(repository.issues ?? []), issue];
804
827
  return issue;
@@ -820,8 +843,11 @@ export class LocalProvider {
820
843
  }
821
844
  if (changes.description !== undefined)
822
845
  issue.description = changes.description;
823
- if (changes.labels !== undefined)
824
- issue.labels = this.cleanList(changes.labels);
846
+ if (changes.labels !== undefined) {
847
+ const labels = this.cleanList(changes.labels);
848
+ issue.labelEvents = [...(issue.labelEvents ?? []), ...this.labelChanges(issue.labels, labels, user.username, new Date().toISOString())];
849
+ issue.labels = labels;
850
+ }
825
851
  if (changes.assignees !== undefined)
826
852
  issue.assignees = this.cleanList(changes.assignees);
827
853
  if (changes.milestone !== undefined)
@@ -896,6 +922,17 @@ export class LocalProvider {
896
922
  toComment(record) {
897
923
  return { id: record.id, author: record.author, body: record.body, createdAt: record.createdAt, updatedAt: record.updatedAt };
898
924
  }
925
+ /** What changed from one set of labels to another, as events. */
926
+ labelChanges(before, after, author, at) {
927
+ return [
928
+ ...before.filter((label) => !after.includes(label)).map((label) => ({ label, action: 'removed', author, createdAt: at })),
929
+ ...after.filter((label) => !before.includes(label)).map((label) => ({ label, action: 'added', author, createdAt: at })),
930
+ ];
931
+ }
932
+ async listIssueLabelEvents({ token, id, number }) {
933
+ const { record } = await this.open(token, id);
934
+ return (this.issueOf(record, number).labelEvents ?? []).map((event) => ({ ...event }));
935
+ }
899
936
  async listIssueComments({ token, id, number }) {
900
937
  const { record } = await this.open(token, id);
901
938
  return this.issueOf(record, number).comments.map((comment) => this.toComment(comment));