@harness-engineering/core 0.18.0 → 0.19.0

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.
package/dist/index.d.mts CHANGED
@@ -5133,6 +5133,8 @@ interface TrackerSyncAdapter {
5133
5133
  fetchAllTickets(): Promise<Result<ExternalTicketState[]>>;
5134
5134
  /** Assign a ticket to a person */
5135
5135
  assignTicket(externalId: string, assignee: string): Promise<Result<void>>;
5136
+ /** Get the authenticated user's login (e.g., "@octocat"). Cached after first call. */
5137
+ getAuthenticatedUser(): Promise<Result<string>>;
5136
5138
  }
5137
5139
  /**
5138
5140
  * Options for sync operations that pull from external.
@@ -5181,6 +5183,8 @@ declare class GitHubIssuesSyncAdapter implements TrackerSyncAdapter {
5181
5183
  private readonly retryOpts;
5182
5184
  /** Cached GitHub milestone name -> ID mapping */
5183
5185
  private milestoneCache;
5186
+ /** Cached authenticated user login (e.g., "@octocat") */
5187
+ private authenticatedUserCache;
5184
5188
  constructor(options: GitHubAdapterOptions);
5185
5189
  /**
5186
5190
  * Fetch all GitHub milestones and build the name -> ID cache.
@@ -5190,6 +5194,7 @@ declare class GitHubIssuesSyncAdapter implements TrackerSyncAdapter {
5190
5194
  * Get or create a GitHub milestone by name. Returns the milestone number.
5191
5195
  */
5192
5196
  private ensureMilestone;
5197
+ getAuthenticatedUser(): Promise<Result<string>>;
5193
5198
  private headers;
5194
5199
  /**
5195
5200
  * Close an issue if the feature status maps to 'closed'.
package/dist/index.d.ts CHANGED
@@ -5133,6 +5133,8 @@ interface TrackerSyncAdapter {
5133
5133
  fetchAllTickets(): Promise<Result<ExternalTicketState[]>>;
5134
5134
  /** Assign a ticket to a person */
5135
5135
  assignTicket(externalId: string, assignee: string): Promise<Result<void>>;
5136
+ /** Get the authenticated user's login (e.g., "@octocat"). Cached after first call. */
5137
+ getAuthenticatedUser(): Promise<Result<string>>;
5136
5138
  }
5137
5139
  /**
5138
5140
  * Options for sync operations that pull from external.
@@ -5181,6 +5183,8 @@ declare class GitHubIssuesSyncAdapter implements TrackerSyncAdapter {
5181
5183
  private readonly retryOpts;
5182
5184
  /** Cached GitHub milestone name -> ID mapping */
5183
5185
  private milestoneCache;
5186
+ /** Cached authenticated user login (e.g., "@octocat") */
5187
+ private authenticatedUserCache;
5184
5188
  constructor(options: GitHubAdapterOptions);
5185
5189
  /**
5186
5190
  * Fetch all GitHub milestones and build the name -> ID cache.
@@ -5190,6 +5194,7 @@ declare class GitHubIssuesSyncAdapter implements TrackerSyncAdapter {
5190
5194
  * Get or create a GitHub milestone by name. Returns the milestone number.
5191
5195
  */
5192
5196
  private ensureMilestone;
5197
+ getAuthenticatedUser(): Promise<Result<string>>;
5193
5198
  private headers;
5194
5199
  /**
5195
5200
  * Close an issue if the feature status maps to 'closed'.
package/dist/index.js CHANGED
@@ -12607,6 +12607,8 @@ var GitHubIssuesSyncAdapter = class {
12607
12607
  retryOpts;
12608
12608
  /** Cached GitHub milestone name -> ID mapping */
12609
12609
  milestoneCache = null;
12610
+ /** Cached authenticated user login (e.g., "@octocat") */
12611
+ authenticatedUserCache = null;
12610
12612
  constructor(options) {
12611
12613
  this.token = options.token;
12612
12614
  this.config = options.config;
@@ -12660,6 +12662,26 @@ var GitHubIssuesSyncAdapter = class {
12660
12662
  cache.set(name, data.number);
12661
12663
  return data.number;
12662
12664
  }
12665
+ async getAuthenticatedUser() {
12666
+ if (this.authenticatedUserCache) return (0, import_types21.Ok)(this.authenticatedUserCache);
12667
+ try {
12668
+ const response = await fetchWithRetry(
12669
+ this.fetchFn,
12670
+ `${this.apiBase}/user`,
12671
+ { method: "GET", headers: this.headers() },
12672
+ this.retryOpts
12673
+ );
12674
+ if (!response.ok) {
12675
+ const text = await response.text();
12676
+ return (0, import_types21.Err)(new Error(`GitHub API error ${response.status}: ${text}`));
12677
+ }
12678
+ const data = await response.json();
12679
+ this.authenticatedUserCache = `@${data.login}`;
12680
+ return (0, import_types21.Ok)(this.authenticatedUserCache);
12681
+ } catch (error) {
12682
+ return (0, import_types21.Err)(error instanceof Error ? error : new Error(String(error)));
12683
+ }
12684
+ }
12663
12685
  headers() {
12664
12686
  return {
12665
12687
  Authorization: `Bearer ${this.token}`,
@@ -12689,6 +12711,10 @@ var GitHubIssuesSyncAdapter = class {
12689
12711
  const milestoneId = await this.ensureMilestone(milestone);
12690
12712
  const issuePayload = { title: feature.name, body, labels };
12691
12713
  if (milestoneId) issuePayload.milestone = milestoneId;
12714
+ if (feature.assignee) {
12715
+ const login = feature.assignee.startsWith("@") ? feature.assignee.slice(1) : feature.assignee;
12716
+ issuePayload.assignees = [login];
12717
+ }
12692
12718
  const response = await fetchWithRetry(
12693
12719
  this.fetchFn,
12694
12720
  `${this.apiBase}/repos/${this.owner}/${this.repo}/issues`,
@@ -12722,6 +12748,14 @@ var GitHubIssuesSyncAdapter = class {
12722
12748
  patch.state = externalStatus;
12723
12749
  patch.labels = [...labelsForStatus(changes.status, this.config), "feature"];
12724
12750
  }
12751
+ if (changes.assignee !== void 0) {
12752
+ if (changes.assignee) {
12753
+ const login = changes.assignee.startsWith("@") ? changes.assignee.slice(1) : changes.assignee;
12754
+ patch.assignees = [login];
12755
+ } else {
12756
+ patch.assignees = [];
12757
+ }
12758
+ }
12725
12759
  if (milestone) {
12726
12760
  const milestoneId = await this.ensureMilestone(milestone);
12727
12761
  if (milestoneId) patch.milestone = milestoneId;
@@ -12846,8 +12880,16 @@ function emptySyncResult() {
12846
12880
  }
12847
12881
  async function syncToExternal(roadmap, adapter, _config) {
12848
12882
  const result = emptySyncResult();
12883
+ let defaultAssignee = null;
12884
+ const userResult = await adapter.getAuthenticatedUser();
12885
+ if (userResult.ok) {
12886
+ defaultAssignee = userResult.value;
12887
+ }
12849
12888
  for (const milestone of roadmap.milestones) {
12850
12889
  for (const feature of milestone.features) {
12890
+ if (!feature.assignee && defaultAssignee) {
12891
+ feature.assignee = defaultAssignee;
12892
+ }
12851
12893
  if (!feature.externalId) {
12852
12894
  const createResult = await adapter.createTicket(feature, milestone.name);
12853
12895
  if (createResult.ok) {
package/dist/index.mjs CHANGED
@@ -10498,6 +10498,8 @@ var GitHubIssuesSyncAdapter = class {
10498
10498
  retryOpts;
10499
10499
  /** Cached GitHub milestone name -> ID mapping */
10500
10500
  milestoneCache = null;
10501
+ /** Cached authenticated user login (e.g., "@octocat") */
10502
+ authenticatedUserCache = null;
10501
10503
  constructor(options) {
10502
10504
  this.token = options.token;
10503
10505
  this.config = options.config;
@@ -10551,6 +10553,26 @@ var GitHubIssuesSyncAdapter = class {
10551
10553
  cache.set(name, data.number);
10552
10554
  return data.number;
10553
10555
  }
10556
+ async getAuthenticatedUser() {
10557
+ if (this.authenticatedUserCache) return Ok4(this.authenticatedUserCache);
10558
+ try {
10559
+ const response = await fetchWithRetry(
10560
+ this.fetchFn,
10561
+ `${this.apiBase}/user`,
10562
+ { method: "GET", headers: this.headers() },
10563
+ this.retryOpts
10564
+ );
10565
+ if (!response.ok) {
10566
+ const text = await response.text();
10567
+ return Err3(new Error(`GitHub API error ${response.status}: ${text}`));
10568
+ }
10569
+ const data = await response.json();
10570
+ this.authenticatedUserCache = `@${data.login}`;
10571
+ return Ok4(this.authenticatedUserCache);
10572
+ } catch (error) {
10573
+ return Err3(error instanceof Error ? error : new Error(String(error)));
10574
+ }
10575
+ }
10554
10576
  headers() {
10555
10577
  return {
10556
10578
  Authorization: `Bearer ${this.token}`,
@@ -10580,6 +10602,10 @@ var GitHubIssuesSyncAdapter = class {
10580
10602
  const milestoneId = await this.ensureMilestone(milestone);
10581
10603
  const issuePayload = { title: feature.name, body, labels };
10582
10604
  if (milestoneId) issuePayload.milestone = milestoneId;
10605
+ if (feature.assignee) {
10606
+ const login = feature.assignee.startsWith("@") ? feature.assignee.slice(1) : feature.assignee;
10607
+ issuePayload.assignees = [login];
10608
+ }
10583
10609
  const response = await fetchWithRetry(
10584
10610
  this.fetchFn,
10585
10611
  `${this.apiBase}/repos/${this.owner}/${this.repo}/issues`,
@@ -10613,6 +10639,14 @@ var GitHubIssuesSyncAdapter = class {
10613
10639
  patch.state = externalStatus;
10614
10640
  patch.labels = [...labelsForStatus(changes.status, this.config), "feature"];
10615
10641
  }
10642
+ if (changes.assignee !== void 0) {
10643
+ if (changes.assignee) {
10644
+ const login = changes.assignee.startsWith("@") ? changes.assignee.slice(1) : changes.assignee;
10645
+ patch.assignees = [login];
10646
+ } else {
10647
+ patch.assignees = [];
10648
+ }
10649
+ }
10616
10650
  if (milestone) {
10617
10651
  const milestoneId = await this.ensureMilestone(milestone);
10618
10652
  if (milestoneId) patch.milestone = milestoneId;
@@ -10737,8 +10771,16 @@ function emptySyncResult() {
10737
10771
  }
10738
10772
  async function syncToExternal(roadmap, adapter, _config) {
10739
10773
  const result = emptySyncResult();
10774
+ let defaultAssignee = null;
10775
+ const userResult = await adapter.getAuthenticatedUser();
10776
+ if (userResult.ok) {
10777
+ defaultAssignee = userResult.value;
10778
+ }
10740
10779
  for (const milestone of roadmap.milestones) {
10741
10780
  for (const feature of milestone.features) {
10781
+ if (!feature.assignee && defaultAssignee) {
10782
+ feature.assignee = defaultAssignee;
10783
+ }
10742
10784
  if (!feature.externalId) {
10743
10785
  const createResult = await adapter.createTicket(feature, milestone.name);
10744
10786
  if (createResult.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@harness-engineering/core",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Core library for Harness Engineering toolkit",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -50,7 +50,7 @@
50
50
  "web-tree-sitter": "^0.24.7",
51
51
  "zod": "^3.25.76",
52
52
  "@harness-engineering/graph": "0.3.5",
53
- "@harness-engineering/types": "0.7.0"
53
+ "@harness-engineering/types": "0.8.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/ejs": "^3.1.5",