@almadar/integrations 2.29.0 → 2.31.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.
@@ -1,4 +1,4 @@
1
- import { g as IntegrationParams, B as BaseIntegration, a as IntegrationConfig, h as IntegrationResult } from '../../BaseIntegration-C_5q54DM.js';
1
+ import { g as IntegrationParams, B as BaseIntegration, a as IntegrationConfig, h as IntegrationResult } from '../../BaseIntegration-BYlbMFlf.js';
2
2
  import '@almadar/core';
3
3
 
4
4
  /**
@@ -184,8 +184,8 @@ interface GitHubListIssuesParams extends IntegrationParams {
184
184
  state?: 'open' | 'closed' | 'all';
185
185
  /** Labels to filter by */
186
186
  labels?: string[];
187
- /** Maximum number of issues to return */
188
- limit?: number;
187
+ /** Page size for the GitHub API request */
188
+ per_page?: number;
189
189
  }
190
190
  /**
191
191
  * GitHub get issue parameters
@@ -194,6 +194,79 @@ interface GitHubGetIssueParams extends IntegrationParams {
194
194
  /** Issue number */
195
195
  issueNumber: number;
196
196
  }
197
+ /**
198
+ * GitHub get file contents parameters
199
+ */
200
+ interface GitHubGetFileParams extends IntegrationParams {
201
+ /** Repository owner */
202
+ owner: string;
203
+ /** Repository name */
204
+ repo: string;
205
+ /** File path within the repository */
206
+ path: string;
207
+ /** Branch, tag, or commit SHA (defaults to the repo's default branch) */
208
+ ref?: string;
209
+ }
210
+ /**
211
+ * GitHub file contents response
212
+ */
213
+ interface GitHubFileContent {
214
+ /** File path within the repository */
215
+ path: string;
216
+ /** Decoded file content */
217
+ content: string;
218
+ /** Blob SHA */
219
+ sha: string;
220
+ /** File size in bytes */
221
+ size: number;
222
+ }
223
+ /**
224
+ * GitHub list commits parameters
225
+ */
226
+ interface GitHubListCommitsParams extends IntegrationParams {
227
+ /** Repository owner */
228
+ owner: string;
229
+ /** Repository name */
230
+ repo: string;
231
+ /** Restrict to commits touching this path */
232
+ path?: string;
233
+ /** Branch, tag, or commit SHA to start listing from */
234
+ ref?: string;
235
+ /** Results per page (GitHub default 30, max 100) */
236
+ per_page?: number;
237
+ }
238
+ /**
239
+ * GitHub commit summary, as returned by the `listCommits` action.
240
+ */
241
+ interface GitHubCommitSummary {
242
+ sha: string;
243
+ message: string;
244
+ author: string;
245
+ date: string;
246
+ }
247
+ /**
248
+ * GitHub create issue parameters
249
+ */
250
+ interface GitHubCreateIssueParams extends IntegrationParams {
251
+ /** Repository owner */
252
+ owner: string;
253
+ /** Repository name */
254
+ repo: string;
255
+ /** Issue title */
256
+ title: string;
257
+ /** Issue body */
258
+ body?: string;
259
+ /** Labels to apply */
260
+ labels?: string[];
261
+ }
262
+ /**
263
+ * GitHub create issue response
264
+ */
265
+ interface GitHubIssueCreated {
266
+ number: number;
267
+ title: string;
268
+ url: string;
269
+ }
197
270
  /**
198
271
  * GitHub pull request response
199
272
  */
@@ -341,6 +414,7 @@ interface GitHubCommit {
341
414
  */
342
415
  declare function listCommits(config: GitHubAPIConfig, options?: {
343
416
  path?: string;
417
+ ref?: string;
344
418
  perPage?: number;
345
419
  page?: number;
346
420
  }): Promise<GitHubCommit[]>;
@@ -353,6 +427,23 @@ declare function getCommitDiff(config: GitHubAPIConfig, sha: string): Promise<st
353
427
  * Returns null if the file doesn't exist at that commit.
354
428
  */
355
429
  declare function getFileAtCommit(config: GitHubAPIConfig, path: string, sha: string): Promise<string | null>;
430
+ /**
431
+ * Get a file's content plus metadata (sha, size) — the `getFile` contract
432
+ * action. Unlike `getFileAtCommit` (raw bytes only, no sha/size), this reads
433
+ * the JSON contents API to satisfy the declared response shape in one call,
434
+ * and takes owner/repo per-call rather than from a pre-resolved config.
435
+ */
436
+ declare function getFile(params: GitHubGetFileParams, token: string): Promise<GitHubFileContent>;
437
+ /**
438
+ * List commits shaped for the `listCommits` contract action — per-call
439
+ * owner/repo, and the flattened author-name + date the declared response
440
+ * requires (the raw API nests author under `commit.author`).
441
+ */
442
+ declare function listCommitsSummary(params: GitHubListCommitsParams, token: string): Promise<GitHubCommitSummary[]>;
443
+ /**
444
+ * Create an issue — the `createIssue` contract action.
445
+ */
446
+ declare function createIssue(params: GitHubCreateIssueParams, token: string): Promise<GitHubIssueCreated>;
356
447
  /**
357
448
  * Parse repository owner and name from URL
358
449
  */
@@ -489,10 +580,23 @@ declare class GitHubIntegration extends BaseIntegration {
489
580
  * Get issue details
490
581
  */
491
582
  private getIssue;
583
+ /**
584
+ * Get a file's content plus metadata (owner/repo are per-call, not the
585
+ * configured default repo)
586
+ */
587
+ private getFile;
588
+ /**
589
+ * List commits (owner/repo are per-call, not the configured default repo)
590
+ */
591
+ private listCommits;
592
+ /**
593
+ * Create an issue (owner/repo are per-call, not the configured default repo)
594
+ */
595
+ private createIssue;
492
596
  /**
493
597
  * Get API config for GitHub API calls
494
598
  */
495
599
  private getAPIConfig;
496
600
  }
497
601
 
498
- export { type GitHubAPIConfig, type GitHubAddRemoteParams, type GitHubCloneParams, type GitHubComment, type GitHubCommit, type GitHubCommitParams, type GitHubCreateBranchParams, type GitHubCreatePRParams, type GitHubCreateRepoParams, type GitHubGetIssueParams, type GitHubGetPRCommentsParams, type GitHubInitParams, GitHubIntegration, type GitHubIssue, type GitHubListIssuesParams, type GitHubPullParams, type GitHubPullRequest, type GitHubPullResult, type GitHubPushParams, type GitHubRateLimit, type GitHubRenameBranchParams, type GitHubRepoCreated, type GitHubSetUserConfigParams, addRemote, cloneRepo, commit, createBranch, createPR, createRepo, getCommitDiff, getCurrentBranch, getFileAtCommit, getHeadCommit, getHeadSha, getIssue, getPRComments, getRateLimit, hasUncommittedChanges, init, listCommits, listIssues, listRepoTree, parseRepoUrl, pull, push, readRepoFile, renameCurrentBranch, setUserConfig };
602
+ export { type GitHubAPIConfig, type GitHubAddRemoteParams, type GitHubCloneParams, type GitHubComment, type GitHubCommit, type GitHubCommitParams, type GitHubCommitSummary, type GitHubCreateBranchParams, type GitHubCreateIssueParams, type GitHubCreatePRParams, type GitHubCreateRepoParams, type GitHubFileContent, type GitHubGetFileParams, type GitHubGetIssueParams, type GitHubGetPRCommentsParams, type GitHubInitParams, GitHubIntegration, type GitHubIssue, type GitHubIssueCreated, type GitHubListCommitsParams, type GitHubListIssuesParams, type GitHubPullParams, type GitHubPullRequest, type GitHubPullResult, type GitHubPushParams, type GitHubRateLimit, type GitHubRenameBranchParams, type GitHubRepoCreated, type GitHubSetUserConfigParams, addRemote, cloneRepo, commit, createBranch, createIssue, createPR, createRepo, getCommitDiff, getCurrentBranch, getFile, getFileAtCommit, getHeadCommit, getHeadSha, getIssue, getPRComments, getRateLimit, hasUncommittedChanges, init, listCommits, listCommitsSummary, listIssues, listRepoTree, parseRepoUrl, pull, push, readRepoFile, renameCurrentBranch, setUserConfig };
@@ -23,6 +23,14 @@ var ConsoleLogger = class {
23
23
  }
24
24
  };
25
25
  var RESERVED_ENVELOPE_KEYS = /* @__PURE__ */ new Set(["emit", "onSuccess", "onError", "timeout"]);
26
+ var UnknownActionError = class extends Error {
27
+ constructor(integration, action) {
28
+ super(`Unknown ${integration} action: ${action}`);
29
+ this.name = "UnknownActionError";
30
+ this.integration = integration;
31
+ this.action = action;
32
+ }
33
+ };
26
34
  function validateParams(integration, action, params) {
27
35
  const typedRegistry = integratorsRegistry;
28
36
  const registry = typedRegistry.integrators[integration];
@@ -666,10 +674,10 @@ async function getPRComments(params, config) {
666
674
  return data;
667
675
  }
668
676
  async function listIssues(params, config) {
669
- const { state = "open", labels = [], limit = 30 } = params;
677
+ const { state = "open", labels = [], per_page = 30 } = params;
670
678
  const queryParams = new URLSearchParams({
671
679
  state,
672
- per_page: Math.min(limit, 100).toString()
680
+ per_page: Math.min(per_page, 100).toString()
673
681
  });
674
682
  if (labels.length > 0) {
675
683
  queryParams.append("labels", labels.join(","));
@@ -694,6 +702,7 @@ async function getRateLimit(config) {
694
702
  async function listCommits(config, options) {
695
703
  const params = new URLSearchParams();
696
704
  if (options?.path) params.set("path", options.path);
705
+ if (options?.ref) params.set("sha", options.ref);
697
706
  if (options?.perPage) params.set("per_page", options.perPage.toString());
698
707
  if (options?.page) params.set("page", options.page.toString());
699
708
  const queryStr = params.toString();
@@ -748,6 +757,36 @@ async function getFileAtCommit(config, path, sha) {
748
757
  );
749
758
  }
750
759
  }
760
+ async function getFile(params, token) {
761
+ const { owner, repo, path, ref } = params;
762
+ const config = { token};
763
+ const query = ref ? `?ref=${encodeURIComponent(ref)}` : "";
764
+ const endpoint = `/repos/${owner}/${repo}/contents/${path}${query}`;
765
+ const { data } = await githubFetch(endpoint, config);
766
+ const content = data.encoding === "base64" ? Buffer.from(data.content, "base64").toString("utf-8") : data.content;
767
+ return { path: data.path, content, sha: data.sha, size: data.size };
768
+ }
769
+ async function listCommitsSummary(params, token) {
770
+ const { owner, repo, path, ref, per_page } = params;
771
+ const config = { token, owner, repo };
772
+ const commits = await listCommits(config, { path, ref, perPage: per_page });
773
+ return commits.map((commit2) => ({
774
+ sha: commit2.sha,
775
+ message: commit2.message,
776
+ author: commit2.author.name,
777
+ date: commit2.author.date
778
+ }));
779
+ }
780
+ async function createIssue(params, token) {
781
+ const { owner, repo, title, body, labels } = params;
782
+ const config = { token};
783
+ const endpoint = `/repos/${owner}/${repo}/issues`;
784
+ const { data } = await githubFetch(endpoint, config, {
785
+ method: "POST",
786
+ body: JSON.stringify({ title, body, labels })
787
+ });
788
+ return { number: data.number, title: data.title, url: data.url };
789
+ }
751
790
  function parseRepoUrl(repoUrl) {
752
791
  try {
753
792
  const url = new URL(repoUrl);
@@ -845,8 +884,23 @@ var GitHubIntegration = class extends BaseIntegration {
845
884
  () => this.getIssue(params)
846
885
  );
847
886
  break;
887
+ case "getFile":
888
+ data = await this.executeWithRetry(
889
+ () => this.getFile(params)
890
+ );
891
+ break;
892
+ case "listCommits":
893
+ data = await this.executeWithRetry(
894
+ () => this.listCommits(params)
895
+ );
896
+ break;
897
+ case "createIssue":
898
+ data = await this.executeWithRetry(
899
+ () => this.createIssue(params)
900
+ );
901
+ break;
848
902
  default:
849
- throw new Error(`Unknown GitHub action: ${action}`);
903
+ throw new UnknownActionError(this.config.name, action);
850
904
  }
851
905
  return {
852
906
  success: true,
@@ -925,7 +979,7 @@ var GitHubIntegration = class extends BaseIntegration {
925
979
  * List issues
926
980
  */
927
981
  async listIssues(params) {
928
- this.logger.debug("Listing issues", { state: params.state, labels: params.labels?.join(", "), limit: params.limit });
982
+ this.logger.debug("Listing issues", { state: params.state, labels: params.labels?.join(", "), per_page: params.per_page });
929
983
  const apiConfig = this.getAPIConfig();
930
984
  const issues = await listIssues(params, apiConfig);
931
985
  return { issues };
@@ -939,6 +993,29 @@ var GitHubIntegration = class extends BaseIntegration {
939
993
  const result = await getIssue(params, apiConfig);
940
994
  return result;
941
995
  }
996
+ /**
997
+ * Get a file's content plus metadata (owner/repo are per-call, not the
998
+ * configured default repo)
999
+ */
1000
+ async getFile(params) {
1001
+ this.logger.debug("Getting file", { owner: params.owner, repo: params.repo, path: params.path });
1002
+ return getFile(params, this.token);
1003
+ }
1004
+ /**
1005
+ * List commits (owner/repo are per-call, not the configured default repo)
1006
+ */
1007
+ async listCommits(params) {
1008
+ this.logger.debug("Listing commits", { owner: params.owner, repo: params.repo, path: params.path });
1009
+ const commits = await listCommitsSummary(params, this.token);
1010
+ return { commits };
1011
+ }
1012
+ /**
1013
+ * Create an issue (owner/repo are per-call, not the configured default repo)
1014
+ */
1015
+ async createIssue(params) {
1016
+ this.logger.debug("Creating issue", { owner: params.owner, repo: params.repo, title: params.title });
1017
+ return createIssue(params, this.token);
1018
+ }
942
1019
  /**
943
1020
  * Get API config for GitHub API calls
944
1021
  */
@@ -956,6 +1033,6 @@ var GitHubIntegration = class extends BaseIntegration {
956
1033
  }
957
1034
  };
958
1035
 
959
- export { GitHubIntegration, addRemote, cloneRepo, commit, createBranch, createPR, createRepo, getCommitDiff, getCurrentBranch, getFileAtCommit, getHeadCommit, getHeadSha, getIssue, getPRComments, getRateLimit, hasUncommittedChanges, init, listCommits, listIssues, listRepoTree, parseRepoUrl, pull, push, readRepoFile, renameCurrentBranch, setUserConfig };
1036
+ export { GitHubIntegration, addRemote, cloneRepo, commit, createBranch, createIssue, createPR, createRepo, getCommitDiff, getCurrentBranch, getFile, getFileAtCommit, getHeadCommit, getHeadSha, getIssue, getPRComments, getRateLimit, hasUncommittedChanges, init, listCommits, listCommitsSummary, listIssues, listRepoTree, parseRepoUrl, pull, push, readRepoFile, renameCurrentBranch, setUserConfig };
960
1037
  //# sourceMappingURL=index.js.map
961
1038
  //# sourceMappingURL=index.js.map