@lobu/cli 6.0.1 → 7.0.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/README.md +20 -27
- package/dist/bundled-skills/lobu/SKILL.md +11 -11
- package/dist/commands/_lib/apply/apply-cmd.d.ts +38 -0
- package/dist/commands/_lib/apply/apply-cmd.d.ts.map +1 -1
- package/dist/commands/_lib/apply/apply-cmd.js +574 -40
- package/dist/commands/_lib/apply/apply-cmd.js.map +1 -1
- package/dist/commands/_lib/apply/client.d.ts +180 -1
- package/dist/commands/_lib/apply/client.d.ts.map +1 -1
- package/dist/commands/_lib/apply/client.js +308 -28
- package/dist/commands/_lib/apply/client.js.map +1 -1
- package/dist/commands/_lib/apply/desired-state.d.ts +134 -3
- package/dist/commands/_lib/apply/desired-state.d.ts.map +1 -1
- package/dist/commands/_lib/apply/desired-state.js +703 -89
- package/dist/commands/_lib/apply/desired-state.js.map +1 -1
- package/dist/commands/_lib/apply/diff.d.ts +61 -3
- package/dist/commands/_lib/apply/diff.d.ts.map +1 -1
- package/dist/commands/_lib/apply/diff.js +382 -92
- package/dist/commands/_lib/apply/diff.js.map +1 -1
- package/dist/commands/_lib/apply/prompt.d.ts +6 -0
- package/dist/commands/_lib/apply/prompt.d.ts.map +1 -1
- package/dist/commands/_lib/apply/prompt.js +16 -0
- package/dist/commands/_lib/apply/prompt.js.map +1 -1
- package/dist/commands/_lib/apply/render.d.ts +9 -0
- package/dist/commands/_lib/apply/render.d.ts.map +1 -1
- package/dist/commands/_lib/apply/render.js +80 -3
- package/dist/commands/_lib/apply/render.js.map +1 -1
- package/dist/commands/agent.d.ts +7 -0
- package/dist/commands/agent.d.ts.map +1 -1
- package/dist/commands/agent.js +65 -1
- package/dist/commands/agent.js.map +1 -1
- package/dist/commands/chat.d.ts +12 -9
- package/dist/commands/chat.d.ts.map +1 -1
- package/dist/commands/chat.js +125 -57
- package/dist/commands/chat.js.map +1 -1
- package/dist/commands/dev.d.ts +23 -7
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +197 -49
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/doctor.d.ts +1 -0
- package/dist/commands/doctor.d.ts.map +1 -1
- package/dist/commands/doctor.js +136 -0
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/eval.d.ts +8 -0
- package/dist/commands/eval.d.ts.map +1 -1
- package/dist/commands/eval.js +72 -6
- package/dist/commands/eval.js.map +1 -1
- package/dist/commands/init.d.ts +22 -5
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +355 -182
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/link.d.ts +11 -0
- package/dist/commands/link.d.ts.map +1 -0
- package/dist/commands/link.js +28 -0
- package/dist/commands/link.js.map +1 -0
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +14 -2
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/memory/_lib/browser-auth-cmd.d.ts.map +1 -1
- package/dist/commands/memory/_lib/browser-auth-cmd.js +3 -3
- package/dist/commands/memory/_lib/browser-auth-cmd.js.map +1 -1
- package/dist/commands/memory/_lib/mcp.d.ts +2 -2
- package/dist/commands/memory/_lib/mcp.d.ts.map +1 -1
- package/dist/commands/memory/_lib/mcp.js +24 -12
- package/dist/commands/memory/_lib/mcp.js.map +1 -1
- package/dist/commands/memory/_lib/openclaw-auth.d.ts +1 -0
- package/dist/commands/memory/_lib/openclaw-auth.d.ts.map +1 -1
- package/dist/commands/memory/_lib/openclaw-auth.js +14 -3
- package/dist/commands/memory/_lib/openclaw-auth.js.map +1 -1
- package/dist/commands/memory/_lib/openclaw-cmd.js +1 -1
- package/dist/commands/memory/_lib/openclaw-cmd.js.map +1 -1
- package/dist/commands/memory/_lib/schema.d.ts +29 -2
- package/dist/commands/memory/_lib/schema.d.ts.map +1 -1
- package/dist/commands/memory/_lib/schema.js +121 -5
- package/dist/commands/memory/_lib/schema.js.map +1 -1
- package/dist/commands/memory/_lib/seed-cmd.d.ts.map +1 -1
- package/dist/commands/memory/_lib/seed-cmd.js +46 -24
- package/dist/commands/memory/_lib/seed-cmd.js.map +1 -1
- package/dist/commands/memory/run.d.ts.map +1 -1
- package/dist/commands/memory/run.js +2 -2
- package/dist/commands/memory/run.js.map +1 -1
- package/dist/commands/org.d.ts +4 -0
- package/dist/commands/org.d.ts.map +1 -1
- package/dist/commands/org.js +10 -0
- package/dist/commands/org.js.map +1 -1
- package/dist/commands/platforms/platform-prompts.d.ts +0 -1
- package/dist/commands/platforms/platform-prompts.d.ts.map +1 -1
- package/dist/commands/platforms/platform-prompts.js +54 -8
- package/dist/commands/platforms/platform-prompts.js.map +1 -1
- package/dist/commands/telemetry.d.ts +10 -0
- package/dist/commands/telemetry.d.ts.map +1 -0
- package/dist/commands/telemetry.js +68 -0
- package/dist/commands/telemetry.js.map +1 -0
- package/dist/commands/token.d.ts +9 -0
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/commands/token.js +54 -0
- package/dist/commands/token.js.map +1 -1
- package/dist/commands/whoami.d.ts.map +1 -1
- package/dist/commands/whoami.js +1 -1
- package/dist/commands/whoami.js.map +1 -1
- package/dist/connectors/README.md +534 -0
- package/dist/connectors/__tests__/browser-scraper-utils.test.ts +186 -0
- package/dist/connectors/apple_health.ts +138 -0
- package/dist/connectors/apple_screen_time.ts +82 -0
- package/dist/connectors/browser-scraper-utils.ts +246 -0
- package/dist/connectors/capterra.ts +277 -0
- package/dist/connectors/g2.ts +290 -0
- package/dist/connectors/github.ts +1530 -0
- package/dist/connectors/glassdoor.ts +295 -0
- package/dist/connectors/gmaps.ts +197 -0
- package/dist/connectors/google_calendar.ts +641 -0
- package/dist/connectors/google_gmail.ts +754 -0
- package/dist/connectors/google_photos.ts +776 -0
- package/dist/connectors/google_play.ts +349 -0
- package/dist/connectors/hackernews.ts +471 -0
- package/dist/connectors/index.ts +28 -0
- package/dist/connectors/ios_appstore.ts +226 -0
- package/dist/connectors/linkedin.ts +494 -0
- package/dist/connectors/local_directory.ts +91 -0
- package/dist/connectors/microsoft_outlook.ts +410 -0
- package/dist/connectors/producthunt.ts +471 -0
- package/dist/connectors/reddit.ts +600 -0
- package/dist/connectors/revolut.ts +572 -0
- package/dist/connectors/rss.ts +448 -0
- package/dist/connectors/spotify.ts +590 -0
- package/dist/connectors/trustpilot.ts +203 -0
- package/dist/connectors/website.ts +629 -0
- package/dist/connectors/whatsapp.ts +1081 -0
- package/dist/connectors/whatsapp_local.ts +125 -0
- package/dist/connectors/x.ts +536 -0
- package/dist/connectors/youtube.ts +666 -0
- package/dist/db/migrations/00000000000000_baseline.sql +4867 -0
- package/dist/db/migrations/20260405193000_add_mcp_sessions.sql +33 -0
- package/dist/db/migrations/20260408120000_remove_system_connectors.sql +48 -0
- package/dist/db/migrations/20260408120001_optional_compiled_code.sql +6 -0
- package/dist/db/migrations/20260409110000_add_active_watcher_run_index.sql +9 -0
- package/dist/db/migrations/20260409130000_connector_default_config.sql +5 -0
- package/dist/db/migrations/20260410120000_add_agent_secrets.sql +25 -0
- package/dist/db/migrations/20260413170000_add_watcher_group_id.sql +67 -0
- package/dist/db/migrations/20260416120000_add_entity_wa_jid_index.sql +14 -0
- package/dist/db/migrations/20260417100000_add_entity_identities.sql +77 -0
- package/dist/db/migrations/20260418100000_add_auth_runs.sql +83 -0
- package/dist/db/migrations/20260418110000_add_runs_created_by_user.sql +18 -0
- package/dist/db/migrations/20260419120000_add_event_identity_indexes.sql +56 -0
- package/dist/db/migrations/20260420120000_extend_reserved_org_slugs.sql +56 -0
- package/dist/db/migrations/20260424030000_add_watcher_run_correlation.sql +52 -0
- package/dist/db/migrations/20260424130000_relax_events_client_id_fk.sql +47 -0
- package/dist/db/migrations/20260425100000_normalize_watcher_feedback.sql +91 -0
- package/dist/db/migrations/20260425120000_add_run_diagnostics.sql +20 -0
- package/dist/db/migrations/20260425130000_add_repair_agent_plumbing.sql +46 -0
- package/dist/db/migrations/20260426120000_entities_entity_type_fk.sql +101 -0
- package/dist/db/migrations/20260426130000_db_integrity_cleanup.sql +104 -0
- package/dist/db/migrations/20260426130001_db_integrity_cleanup_concurrent.sql +187 -0
- package/dist/db/migrations/20260427133000_events_created_by_nullable.sql +74 -0
- package/dist/db/migrations/20260427140000_identity_engine_indexes.sql +140 -0
- package/dist/db/migrations/20260427150000_drop_events_source_id.sql +177 -0
- package/dist/db/migrations/20260427160000_drop_dead_schema.sql +76 -0
- package/dist/db/migrations/20260427170000_market_founder_to_member.sql +364 -0
- package/dist/db/migrations/20260428040000_cascade_events_watchers_org_fk.sql +66 -0
- package/dist/db/migrations/20260428050000_add_runs_approved_input.sql +9 -0
- package/dist/db/migrations/20260429010000_auth_profile_tenant_scoped_fk.sql +79 -0
- package/dist/db/migrations/20260429060000_extend_runs_for_lobu_queue.sql +108 -0
- package/dist/db/migrations/20260429120000_agent_changed_notify.sql +97 -0
- package/dist/db/migrations/20260429120100_user_auth_profiles_and_model_prefs.sql +36 -0
- package/dist/db/migrations/20260429120200_fix_notify_old_keys.sql +130 -0
- package/dist/db/migrations/20260429130000_oauth_states_cli_sessions_rate_limits.sql +83 -0
- package/dist/db/migrations/20260429140000_phase8_grants_chat_connections_mcp_sessions.sql +84 -0
- package/dist/db/migrations/20260429140100_runs_priority_expires_at_retry_delay.sql +44 -0
- package/dist/db/migrations/20260429180000_drop_invalidatable_cache_triggers.sql +25 -0
- package/dist/db/migrations/20260430005614_agents_apply_fields.sql +21 -0
- package/dist/db/migrations/20260430022231_fix_connection_config_encryption.sql +69 -0
- package/dist/db/migrations/20260430151215_add_task_run_type.sql +77 -0
- package/dist/db/migrations/20260501000000_drop_cli_sessions.sql +27 -0
- package/dist/db/migrations/20260501133000_lobu_memory_mcp_id.sql +117 -0
- package/dist/db/migrations/20260502000000_drop_chat_connections.sql +60 -0
- package/dist/db/migrations/20260503000000_agent_secrets_org_scope.sql +56 -0
- package/dist/db/migrations/20260504000000_flatten_agents_drop_sandbox_model.sql +48 -0
- package/dist/db/migrations/20260510220000_connector_required_capability.sql +47 -0
- package/dist/db/migrations/20260512000000_device_worker_connection_binding.sql +113 -0
- package/dist/db/migrations/20260512131703_connections_slug.sql +131 -0
- package/dist/db/migrations/20260513000000_chat_user_identities.sql +24 -0
- package/dist/db/migrations/20260513120000_auth_profiles_device_binding.sql +50 -0
- package/dist/db/migrations/20260513150000_auth_profiles_cdp_url.sql +43 -0
- package/dist/db/migrations/20260513200000_notifications_as_events.sql +86 -0
- package/dist/db/migrations/20260514000000_scheduled_jobs.sql +97 -0
- package/dist/db/migrations/20260514120000_auth_profiles_connector_key_nullable.sql +42 -0
- package/dist/eval/types.d.ts +2 -0
- package/dist/eval/types.d.ts.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +210 -132
- package/dist/index.js.map +1 -1
- package/dist/internal/api-client.d.ts +4 -8
- package/dist/internal/api-client.d.ts.map +1 -1
- package/dist/internal/api-client.js +1 -1
- package/dist/internal/api-client.js.map +1 -1
- package/dist/internal/context.js +2 -2
- package/dist/internal/context.js.map +1 -1
- package/dist/internal/credentials.d.ts.map +1 -1
- package/dist/internal/credentials.js +6 -1
- package/dist/internal/credentials.js.map +1 -1
- package/dist/internal/gateway-url.d.ts +14 -0
- package/dist/internal/gateway-url.d.ts.map +1 -1
- package/dist/internal/gateway-url.js +19 -0
- package/dist/internal/gateway-url.js.map +1 -1
- package/dist/internal/index.d.ts +3 -4
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +3 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/oauth.d.ts +6 -5
- package/dist/internal/oauth.d.ts.map +1 -1
- package/dist/internal/oauth.js +2 -2
- package/dist/internal/project-link.d.ts +10 -0
- package/dist/internal/project-link.d.ts.map +1 -0
- package/dist/internal/project-link.js +48 -0
- package/dist/internal/project-link.js.map +1 -0
- package/dist/providers.json +2 -2
- package/dist/server.bundle.mjs +31654 -30866
- package/dist/start-local.bundle.mjs +74409 -0
- package/dist/templates/README.md.tmpl +10 -11
- package/dist/templates/TESTING.md.tmpl +9 -9
- package/package.json +15 -13
- package/dist/__tests__/chat.integration.test.d.ts +0 -2
- package/dist/__tests__/chat.integration.test.d.ts.map +0 -1
- package/dist/__tests__/chat.integration.test.js +0 -337
- package/dist/__tests__/chat.integration.test.js.map +0 -1
- package/dist/__tests__/dev.test.d.ts +0 -2
- package/dist/__tests__/dev.test.d.ts.map +0 -1
- package/dist/__tests__/dev.test.js +0 -25
- package/dist/__tests__/dev.test.js.map +0 -1
- package/dist/__tests__/init-memory.test.d.ts +0 -2
- package/dist/__tests__/init-memory.test.d.ts.map +0 -1
- package/dist/__tests__/init-memory.test.js +0 -45
- package/dist/__tests__/init-memory.test.js.map +0 -1
- package/dist/__tests__/token.test.d.ts +0 -2
- package/dist/__tests__/token.test.d.ts.map +0 -1
- package/dist/__tests__/token.test.js +0 -52
- package/dist/__tests__/token.test.js.map +0 -1
- package/dist/commands/_lib/apply/__tests__/client.test.d.ts +0 -2
- package/dist/commands/_lib/apply/__tests__/client.test.d.ts.map +0 -1
- package/dist/commands/_lib/apply/__tests__/client.test.js +0 -23
- package/dist/commands/_lib/apply/__tests__/client.test.js.map +0 -1
- package/dist/commands/_lib/apply/__tests__/desired-state.test.d.ts +0 -2
- package/dist/commands/_lib/apply/__tests__/desired-state.test.d.ts.map +0 -1
- package/dist/commands/_lib/apply/__tests__/desired-state.test.js +0 -140
- package/dist/commands/_lib/apply/__tests__/desired-state.test.js.map +0 -1
- package/dist/commands/_lib/apply/__tests__/diff.test.d.ts +0 -2
- package/dist/commands/_lib/apply/__tests__/diff.test.d.ts.map +0 -1
- package/dist/commands/_lib/apply/__tests__/diff.test.js +0 -378
- package/dist/commands/_lib/apply/__tests__/diff.test.js.map +0 -1
- package/dist/commands/apply.d.ts +0 -3
- package/dist/commands/apply.d.ts.map +0 -1
- package/dist/commands/apply.js +0 -5
- package/dist/commands/apply.js.map +0 -1
- package/dist/commands/memory/_lib/openclaw-auth.test.d.ts +0 -2
- package/dist/commands/memory/_lib/openclaw-auth.test.d.ts.map +0 -1
- package/dist/commands/memory/_lib/openclaw-auth.test.js +0 -9
- package/dist/commands/memory/_lib/openclaw-auth.test.js.map +0 -1
- package/dist/internal/__tests__/api-client.test.d.ts +0 -2
- package/dist/internal/__tests__/api-client.test.d.ts.map +0 -1
- package/dist/internal/__tests__/api-client.test.js +0 -95
- package/dist/internal/__tests__/api-client.test.js.map +0 -1
- package/dist/internal/__tests__/context.test.d.ts +0 -2
- package/dist/internal/__tests__/context.test.d.ts.map +0 -1
- package/dist/internal/__tests__/context.test.js +0 -77
- package/dist/internal/__tests__/context.test.js.map +0 -1
|
@@ -0,0 +1,1530 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GitHub Connector (V1 runtime)
|
|
3
|
+
*
|
|
4
|
+
* Syncs GitHub repository content and executes write actions.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type ActionContext,
|
|
9
|
+
type ActionResult,
|
|
10
|
+
type ConnectorDefinition,
|
|
11
|
+
ConnectorRuntime,
|
|
12
|
+
type EventEnvelope,
|
|
13
|
+
IDENTITY,
|
|
14
|
+
type SyncContext,
|
|
15
|
+
type SyncResult,
|
|
16
|
+
} from '@lobu/connector-sdk';
|
|
17
|
+
|
|
18
|
+
type GitHubContentType =
|
|
19
|
+
| 'issues'
|
|
20
|
+
| 'pull_requests'
|
|
21
|
+
| 'issue_comments'
|
|
22
|
+
| 'pr_comments'
|
|
23
|
+
| 'discussions'
|
|
24
|
+
| 'discussion_comments'
|
|
25
|
+
| 'stargazers';
|
|
26
|
+
|
|
27
|
+
interface GitHubConfig {
|
|
28
|
+
repo_owner?: string;
|
|
29
|
+
repo_name?: string;
|
|
30
|
+
content_type?: GitHubContentType;
|
|
31
|
+
lookback_days?: number;
|
|
32
|
+
labels_filter?: string[];
|
|
33
|
+
env_overrides?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface GitHubCheckpoint {
|
|
37
|
+
last_sync_at?: string;
|
|
38
|
+
stargazers?: GitHubStargazerCheckpoint[];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface GitHubStargazerCheckpoint {
|
|
42
|
+
key: string;
|
|
43
|
+
login: string;
|
|
44
|
+
starred_at?: string;
|
|
45
|
+
user_id?: number | null;
|
|
46
|
+
user_type?: string | null;
|
|
47
|
+
html_url?: string | null;
|
|
48
|
+
profile_fetched_at?: string | null;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface RepoRef {
|
|
52
|
+
owner: string;
|
|
53
|
+
repo: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface GitHubMutationResponse {
|
|
57
|
+
id: number;
|
|
58
|
+
number: number;
|
|
59
|
+
html_url: string;
|
|
60
|
+
state: string;
|
|
61
|
+
draft?: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
interface GitHubRepositoryLike {
|
|
65
|
+
id?: number;
|
|
66
|
+
full_name?: string;
|
|
67
|
+
html_url?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
interface GitHubIssueLike {
|
|
71
|
+
id: number;
|
|
72
|
+
number: number;
|
|
73
|
+
title: string;
|
|
74
|
+
body: string | null;
|
|
75
|
+
user?: { login?: string };
|
|
76
|
+
html_url: string;
|
|
77
|
+
created_at: string;
|
|
78
|
+
updated_at: string;
|
|
79
|
+
state: string;
|
|
80
|
+
labels?: Array<{ name?: string }>;
|
|
81
|
+
comments?: number;
|
|
82
|
+
reactions?: { '+1'?: number; '-1'?: number; total_count?: number };
|
|
83
|
+
pull_request?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface GitHubCommentLike {
|
|
87
|
+
id: number;
|
|
88
|
+
body: string;
|
|
89
|
+
user?: { login?: string };
|
|
90
|
+
html_url: string;
|
|
91
|
+
issue_url?: string;
|
|
92
|
+
pull_request_url?: string;
|
|
93
|
+
created_at: string;
|
|
94
|
+
updated_at: string;
|
|
95
|
+
reactions?: { '+1'?: number; '-1'?: number; total_count?: number };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface GraphQLDiscussionNode {
|
|
99
|
+
id: string;
|
|
100
|
+
number: number;
|
|
101
|
+
title: string;
|
|
102
|
+
body: string;
|
|
103
|
+
author?: { login?: string };
|
|
104
|
+
url: string;
|
|
105
|
+
createdAt: string;
|
|
106
|
+
updatedAt: string;
|
|
107
|
+
category?: { name?: string };
|
|
108
|
+
comments?: { totalCount?: number };
|
|
109
|
+
reactions?: { totalCount?: number };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
interface GraphQLDiscussionCommentNode {
|
|
113
|
+
id: string;
|
|
114
|
+
body: string;
|
|
115
|
+
author?: { login?: string };
|
|
116
|
+
url: string;
|
|
117
|
+
createdAt: string;
|
|
118
|
+
updatedAt: string;
|
|
119
|
+
reactions?: { totalCount?: number };
|
|
120
|
+
discussion?: { number?: number };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface GitHubStargazerLike {
|
|
124
|
+
starred_at?: string;
|
|
125
|
+
user?: {
|
|
126
|
+
id?: number;
|
|
127
|
+
login?: string;
|
|
128
|
+
html_url?: string;
|
|
129
|
+
type?: string;
|
|
130
|
+
site_admin?: boolean;
|
|
131
|
+
avatar_url?: string;
|
|
132
|
+
};
|
|
133
|
+
login?: string;
|
|
134
|
+
html_url?: string;
|
|
135
|
+
id?: number;
|
|
136
|
+
type?: string;
|
|
137
|
+
site_admin?: boolean;
|
|
138
|
+
avatar_url?: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface GitHubUserProfile {
|
|
142
|
+
id?: number;
|
|
143
|
+
login?: string;
|
|
144
|
+
name?: string | null;
|
|
145
|
+
company?: string | null;
|
|
146
|
+
blog?: string | null;
|
|
147
|
+
location?: string | null;
|
|
148
|
+
email?: string | null;
|
|
149
|
+
bio?: string | null;
|
|
150
|
+
twitter_username?: string | null;
|
|
151
|
+
public_repos?: number;
|
|
152
|
+
public_gists?: number;
|
|
153
|
+
followers?: number;
|
|
154
|
+
following?: number;
|
|
155
|
+
html_url?: string;
|
|
156
|
+
avatar_url?: string;
|
|
157
|
+
type?: string;
|
|
158
|
+
site_admin?: boolean;
|
|
159
|
+
created_at?: string;
|
|
160
|
+
updated_at?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function toInt(value: unknown, fallback: number): number {
|
|
164
|
+
const n = typeof value === 'number' ? value : Number(value);
|
|
165
|
+
return Number.isFinite(n) ? n : fallback;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function asString(value: unknown): string | undefined {
|
|
169
|
+
return typeof value === 'string' && value.trim().length > 0 ? value : undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function toIsoOrUndefined(value: unknown): string | undefined {
|
|
173
|
+
const str = asString(value);
|
|
174
|
+
if (!str) return undefined;
|
|
175
|
+
const parsed = new Date(str);
|
|
176
|
+
return Number.isNaN(parsed.getTime()) ? undefined : parsed.toISOString();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const REPO_PROPS = {
|
|
180
|
+
repo_owner: { type: 'string', minLength: 1, description: 'Repository owner' },
|
|
181
|
+
repo_name: { type: 'string', minLength: 1, description: 'Repository name' },
|
|
182
|
+
} as const;
|
|
183
|
+
|
|
184
|
+
const LOOKBACK_PROP = {
|
|
185
|
+
lookback_days: {
|
|
186
|
+
type: 'integer',
|
|
187
|
+
minimum: 1,
|
|
188
|
+
maximum: 730,
|
|
189
|
+
default: 365,
|
|
190
|
+
description: 'Initial sync lookback window',
|
|
191
|
+
},
|
|
192
|
+
} as const;
|
|
193
|
+
|
|
194
|
+
const STARGAZER_PROFILE_REFRESH_MS = 30 * 24 * 60 * 60 * 1000;
|
|
195
|
+
const STARGAZER_PROFILE_FETCH_LIMIT = 25;
|
|
196
|
+
|
|
197
|
+
const LABELS_PROP = {
|
|
198
|
+
labels_filter: {
|
|
199
|
+
type: 'array',
|
|
200
|
+
items: { type: 'string' },
|
|
201
|
+
description: 'Optional label filter',
|
|
202
|
+
},
|
|
203
|
+
} as const;
|
|
204
|
+
|
|
205
|
+
export default class GitHubConnector extends ConnectorRuntime {
|
|
206
|
+
readonly definition: ConnectorDefinition = {
|
|
207
|
+
key: 'github',
|
|
208
|
+
name: 'GitHub',
|
|
209
|
+
description: 'Collects GitHub issues/discussions and executes repo actions.',
|
|
210
|
+
version: '1.2.0',
|
|
211
|
+
authSchema: {
|
|
212
|
+
methods: [
|
|
213
|
+
{
|
|
214
|
+
type: 'oauth',
|
|
215
|
+
provider: 'github',
|
|
216
|
+
requiredScopes: ['read:user'],
|
|
217
|
+
optionalScopes: ['repo'],
|
|
218
|
+
loginScopes: ['read:user', 'user:email'],
|
|
219
|
+
clientIdKey: 'GITHUB_CLIENT_ID',
|
|
220
|
+
clientSecretKey: 'GITHUB_CLIENT_SECRET',
|
|
221
|
+
tokenUrl: 'https://github.com/login/oauth/access_token',
|
|
222
|
+
tokenEndpointAuthMethod: 'client_secret_post',
|
|
223
|
+
required: false,
|
|
224
|
+
description:
|
|
225
|
+
'GitHub OAuth enables repo access for this connection. Upgrade to the optional repo scope for private repositories and write actions.',
|
|
226
|
+
loginProvisioning: {
|
|
227
|
+
autoCreateConnection: true,
|
|
228
|
+
},
|
|
229
|
+
setupInstructions:
|
|
230
|
+
'Create a GitHub OAuth App in GitHub Settings > Developer settings > OAuth Apps. Set the authorization callback URL to {{redirect_uri}}, then copy the client ID and client secret below.',
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
type: 'env_keys',
|
|
234
|
+
required: false,
|
|
235
|
+
description: 'Optional fallback token for sync/action calls.',
|
|
236
|
+
fields: [
|
|
237
|
+
{
|
|
238
|
+
key: 'GITHUB_TOKEN',
|
|
239
|
+
label: 'GitHub Token',
|
|
240
|
+
description: 'Personal access token used as fallback auth for API requests.',
|
|
241
|
+
secret: true,
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
},
|
|
247
|
+
feeds: {
|
|
248
|
+
issues: {
|
|
249
|
+
key: 'issues',
|
|
250
|
+
name: 'Issues',
|
|
251
|
+
requiredScopes: [],
|
|
252
|
+
description: 'Sync GitHub issues from a repository.',
|
|
253
|
+
displayNameTemplate: '{repo_owner}/{repo_name} issues',
|
|
254
|
+
configSchema: {
|
|
255
|
+
type: 'object',
|
|
256
|
+
required: ['repo_owner', 'repo_name'],
|
|
257
|
+
properties: { ...REPO_PROPS, ...LABELS_PROP, ...LOOKBACK_PROP },
|
|
258
|
+
},
|
|
259
|
+
eventKinds: {
|
|
260
|
+
issue: {
|
|
261
|
+
description: 'A GitHub issue',
|
|
262
|
+
metadataSchema: {
|
|
263
|
+
type: 'object',
|
|
264
|
+
properties: {
|
|
265
|
+
number: { type: 'number' },
|
|
266
|
+
state: { type: 'string' },
|
|
267
|
+
labels: { type: 'array', items: { type: 'string' } },
|
|
268
|
+
updated_at: { type: 'string' },
|
|
269
|
+
reactions: { type: 'object' },
|
|
270
|
+
comments: { type: 'number' },
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
},
|
|
276
|
+
pull_requests: {
|
|
277
|
+
key: 'pull_requests',
|
|
278
|
+
name: 'Pull Requests',
|
|
279
|
+
requiredScopes: [],
|
|
280
|
+
description: 'Sync GitHub pull requests from a repository.',
|
|
281
|
+
displayNameTemplate: '{repo_owner}/{repo_name} PRs',
|
|
282
|
+
configSchema: {
|
|
283
|
+
type: 'object',
|
|
284
|
+
required: ['repo_owner', 'repo_name'],
|
|
285
|
+
properties: { ...REPO_PROPS, ...LABELS_PROP, ...LOOKBACK_PROP },
|
|
286
|
+
},
|
|
287
|
+
eventKinds: {
|
|
288
|
+
pull_request: {
|
|
289
|
+
description: 'A GitHub pull request',
|
|
290
|
+
metadataSchema: {
|
|
291
|
+
type: 'object',
|
|
292
|
+
properties: {
|
|
293
|
+
number: { type: 'number' },
|
|
294
|
+
state: { type: 'string' },
|
|
295
|
+
labels: { type: 'array', items: { type: 'string' } },
|
|
296
|
+
updated_at: { type: 'string' },
|
|
297
|
+
reactions: { type: 'object' },
|
|
298
|
+
comments: { type: 'number' },
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
issue_comments: {
|
|
305
|
+
key: 'issue_comments',
|
|
306
|
+
name: 'Issue Comments',
|
|
307
|
+
requiredScopes: [],
|
|
308
|
+
description: 'Sync comments on GitHub issues.',
|
|
309
|
+
displayNameTemplate: '{repo_owner}/{repo_name} issue comments',
|
|
310
|
+
configSchema: {
|
|
311
|
+
type: 'object',
|
|
312
|
+
required: ['repo_owner', 'repo_name'],
|
|
313
|
+
properties: { ...REPO_PROPS, ...LOOKBACK_PROP },
|
|
314
|
+
},
|
|
315
|
+
eventKinds: {
|
|
316
|
+
issue_comment: {
|
|
317
|
+
description: 'A comment on a GitHub issue',
|
|
318
|
+
metadataSchema: {
|
|
319
|
+
type: 'object',
|
|
320
|
+
properties: {
|
|
321
|
+
updated_at: { type: 'string' },
|
|
322
|
+
reactions: { type: 'object' },
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
},
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
pr_comments: {
|
|
329
|
+
key: 'pr_comments',
|
|
330
|
+
name: 'PR Comments',
|
|
331
|
+
requiredScopes: [],
|
|
332
|
+
description: 'Sync comments on GitHub pull requests.',
|
|
333
|
+
displayNameTemplate: '{repo_owner}/{repo_name} PR comments',
|
|
334
|
+
configSchema: {
|
|
335
|
+
type: 'object',
|
|
336
|
+
required: ['repo_owner', 'repo_name'],
|
|
337
|
+
properties: { ...REPO_PROPS, ...LOOKBACK_PROP },
|
|
338
|
+
},
|
|
339
|
+
eventKinds: {
|
|
340
|
+
pr_comment: {
|
|
341
|
+
description: 'A comment on a GitHub pull request',
|
|
342
|
+
metadataSchema: {
|
|
343
|
+
type: 'object',
|
|
344
|
+
properties: {
|
|
345
|
+
updated_at: { type: 'string' },
|
|
346
|
+
reactions: { type: 'object' },
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
discussions: {
|
|
353
|
+
key: 'discussions',
|
|
354
|
+
name: 'Discussions',
|
|
355
|
+
requiredScopes: [],
|
|
356
|
+
description: 'Sync GitHub discussions from a repository.',
|
|
357
|
+
displayNameTemplate: '{repo_owner}/{repo_name} discussions',
|
|
358
|
+
configSchema: {
|
|
359
|
+
type: 'object',
|
|
360
|
+
required: ['repo_owner', 'repo_name'],
|
|
361
|
+
properties: { ...REPO_PROPS, ...LOOKBACK_PROP },
|
|
362
|
+
},
|
|
363
|
+
eventKinds: {
|
|
364
|
+
discussion: {
|
|
365
|
+
description: 'A GitHub discussion',
|
|
366
|
+
metadataSchema: {
|
|
367
|
+
type: 'object',
|
|
368
|
+
properties: {
|
|
369
|
+
number: { type: 'number' },
|
|
370
|
+
category: { type: 'string' },
|
|
371
|
+
updated_at: { type: 'string' },
|
|
372
|
+
comments: { type: 'number' },
|
|
373
|
+
reactions: { type: 'number' },
|
|
374
|
+
},
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
discussion_comments: {
|
|
380
|
+
key: 'discussion_comments',
|
|
381
|
+
name: 'Discussion Comments',
|
|
382
|
+
requiredScopes: [],
|
|
383
|
+
description: 'Sync comments on GitHub discussions.',
|
|
384
|
+
displayNameTemplate: '{repo_owner}/{repo_name} discussion comments',
|
|
385
|
+
configSchema: {
|
|
386
|
+
type: 'object',
|
|
387
|
+
required: ['repo_owner', 'repo_name'],
|
|
388
|
+
properties: { ...REPO_PROPS, ...LOOKBACK_PROP },
|
|
389
|
+
},
|
|
390
|
+
eventKinds: {
|
|
391
|
+
discussion_comment: {
|
|
392
|
+
description: 'A comment on a GitHub discussion',
|
|
393
|
+
metadataSchema: {
|
|
394
|
+
type: 'object',
|
|
395
|
+
properties: {
|
|
396
|
+
discussion_number: { type: 'number' },
|
|
397
|
+
updated_at: { type: 'string' },
|
|
398
|
+
reactions: { type: 'number' },
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
},
|
|
402
|
+
},
|
|
403
|
+
},
|
|
404
|
+
stargazers: {
|
|
405
|
+
key: 'stargazers',
|
|
406
|
+
name: 'Stargazers',
|
|
407
|
+
requiredScopes: [],
|
|
408
|
+
description: 'Sync GitHub users who starred a repository.',
|
|
409
|
+
displayNameTemplate: '{repo_owner}/{repo_name} stargazers',
|
|
410
|
+
configSchema: {
|
|
411
|
+
type: 'object',
|
|
412
|
+
required: ['repo_owner', 'repo_name'],
|
|
413
|
+
properties: { ...REPO_PROPS, ...LOOKBACK_PROP },
|
|
414
|
+
},
|
|
415
|
+
eventKinds: {
|
|
416
|
+
stargazer: {
|
|
417
|
+
description: 'A GitHub user starred the repository',
|
|
418
|
+
metadataSchema: {
|
|
419
|
+
type: 'object',
|
|
420
|
+
properties: {
|
|
421
|
+
actor: { type: 'object' },
|
|
422
|
+
target: { type: 'object' },
|
|
423
|
+
action: { type: 'string' },
|
|
424
|
+
starred_at: { type: 'string' },
|
|
425
|
+
source: { type: 'string' },
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
stargazer_unstarred: {
|
|
430
|
+
description: 'A GitHub user unstarred the repository',
|
|
431
|
+
metadataSchema: {
|
|
432
|
+
type: 'object',
|
|
433
|
+
properties: {
|
|
434
|
+
actor: { type: 'object' },
|
|
435
|
+
target: { type: 'object' },
|
|
436
|
+
action: { type: 'string' },
|
|
437
|
+
starred_at: { type: 'string' },
|
|
438
|
+
unstarred_at: { type: 'string' },
|
|
439
|
+
unstarred_at_is_inferred: { type: 'boolean' },
|
|
440
|
+
source: { type: 'string' },
|
|
441
|
+
},
|
|
442
|
+
},
|
|
443
|
+
},
|
|
444
|
+
stargazer_profile: {
|
|
445
|
+
description: 'A public GitHub profile observation for a stargazer',
|
|
446
|
+
metadataSchema: {
|
|
447
|
+
type: 'object',
|
|
448
|
+
properties: {
|
|
449
|
+
public_identity_profile: { type: 'boolean' },
|
|
450
|
+
provider: { type: 'string' },
|
|
451
|
+
identities: { type: 'array' },
|
|
452
|
+
account: { type: 'object' },
|
|
453
|
+
},
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
},
|
|
459
|
+
actions: {
|
|
460
|
+
create_issue: {
|
|
461
|
+
key: 'create_issue',
|
|
462
|
+
name: 'Create Issue',
|
|
463
|
+
description: 'Create a new issue in the configured repository.',
|
|
464
|
+
requiresApproval: true,
|
|
465
|
+
inputSchema: {
|
|
466
|
+
type: 'object',
|
|
467
|
+
required: ['title'],
|
|
468
|
+
properties: {
|
|
469
|
+
title: { type: 'string' },
|
|
470
|
+
body: { type: 'string' },
|
|
471
|
+
labels: { type: 'array', items: { type: 'string' } },
|
|
472
|
+
assignees: { type: 'array', items: { type: 'string' } },
|
|
473
|
+
repo_owner: { type: 'string' },
|
|
474
|
+
repo_name: { type: 'string' },
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
},
|
|
478
|
+
add_issue_comment: {
|
|
479
|
+
key: 'add_issue_comment',
|
|
480
|
+
name: 'Add Issue Comment',
|
|
481
|
+
description: 'Add a comment to an issue or pull request.',
|
|
482
|
+
requiresApproval: true,
|
|
483
|
+
inputSchema: {
|
|
484
|
+
type: 'object',
|
|
485
|
+
required: ['issue_number', 'body'],
|
|
486
|
+
properties: {
|
|
487
|
+
issue_number: { type: 'integer' },
|
|
488
|
+
body: { type: 'string' },
|
|
489
|
+
repo_owner: { type: 'string' },
|
|
490
|
+
repo_name: { type: 'string' },
|
|
491
|
+
},
|
|
492
|
+
},
|
|
493
|
+
},
|
|
494
|
+
close_issue: {
|
|
495
|
+
key: 'close_issue',
|
|
496
|
+
name: 'Close Issue',
|
|
497
|
+
description: 'Close an issue by number.',
|
|
498
|
+
requiresApproval: true,
|
|
499
|
+
inputSchema: {
|
|
500
|
+
type: 'object',
|
|
501
|
+
required: ['issue_number'],
|
|
502
|
+
properties: {
|
|
503
|
+
issue_number: { type: 'integer' },
|
|
504
|
+
repo_owner: { type: 'string' },
|
|
505
|
+
repo_name: { type: 'string' },
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
},
|
|
509
|
+
reopen_issue: {
|
|
510
|
+
key: 'reopen_issue',
|
|
511
|
+
name: 'Reopen Issue',
|
|
512
|
+
description: 'Reopen an issue by number.',
|
|
513
|
+
requiresApproval: true,
|
|
514
|
+
inputSchema: {
|
|
515
|
+
type: 'object',
|
|
516
|
+
required: ['issue_number'],
|
|
517
|
+
properties: {
|
|
518
|
+
issue_number: { type: 'integer' },
|
|
519
|
+
repo_owner: { type: 'string' },
|
|
520
|
+
repo_name: { type: 'string' },
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
create_pull_request: {
|
|
525
|
+
key: 'create_pull_request',
|
|
526
|
+
name: 'Create Pull Request',
|
|
527
|
+
description: 'Create a pull request from head to base branch.',
|
|
528
|
+
requiresApproval: true,
|
|
529
|
+
inputSchema: {
|
|
530
|
+
type: 'object',
|
|
531
|
+
required: ['title', 'head', 'base'],
|
|
532
|
+
properties: {
|
|
533
|
+
title: { type: 'string' },
|
|
534
|
+
head: { type: 'string' },
|
|
535
|
+
base: { type: 'string' },
|
|
536
|
+
body: { type: 'string' },
|
|
537
|
+
draft: { type: 'boolean' },
|
|
538
|
+
repo_owner: { type: 'string' },
|
|
539
|
+
repo_name: { type: 'string' },
|
|
540
|
+
},
|
|
541
|
+
},
|
|
542
|
+
},
|
|
543
|
+
merge_pull_request: {
|
|
544
|
+
key: 'merge_pull_request',
|
|
545
|
+
name: 'Merge Pull Request',
|
|
546
|
+
description: 'Merge a pull request by number.',
|
|
547
|
+
requiresApproval: true,
|
|
548
|
+
inputSchema: {
|
|
549
|
+
type: 'object',
|
|
550
|
+
required: ['pull_number'],
|
|
551
|
+
properties: {
|
|
552
|
+
pull_number: { type: 'integer' },
|
|
553
|
+
merge_method: {
|
|
554
|
+
type: 'string',
|
|
555
|
+
enum: ['merge', 'squash', 'rebase'],
|
|
556
|
+
},
|
|
557
|
+
commit_title: { type: 'string' },
|
|
558
|
+
commit_message: { type: 'string' },
|
|
559
|
+
repo_owner: { type: 'string' },
|
|
560
|
+
repo_name: { type: 'string' },
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
},
|
|
565
|
+
optionsSchema: {
|
|
566
|
+
type: 'object',
|
|
567
|
+
required: ['repo_owner', 'repo_name'],
|
|
568
|
+
properties: { ...REPO_PROPS, ...LABELS_PROP, ...LOOKBACK_PROP },
|
|
569
|
+
},
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
async sync(ctx: SyncContext): Promise<SyncResult> {
|
|
573
|
+
const config = ctx.config as GitHubConfig;
|
|
574
|
+
const repo = this.resolveRepo(config, {});
|
|
575
|
+
const token = this.resolveToken(ctx.credentials?.accessToken, config);
|
|
576
|
+
const contentType = (ctx.feedKey ?? 'issues') as GitHubContentType;
|
|
577
|
+
const sinceIso = this.resolveSince(ctx.checkpoint, config.lookback_days ?? 365);
|
|
578
|
+
|
|
579
|
+
if (contentType === 'stargazers') {
|
|
580
|
+
const result = await this.syncStargazers(repo, ctx.checkpoint, token);
|
|
581
|
+
return {
|
|
582
|
+
events: result.events,
|
|
583
|
+
checkpoint: {
|
|
584
|
+
last_sync_at: new Date().toISOString(),
|
|
585
|
+
stargazers: result.currentStargazers,
|
|
586
|
+
} as Record<string, unknown>,
|
|
587
|
+
metadata: {
|
|
588
|
+
items_found: result.events.length,
|
|
589
|
+
current_stargazers: result.currentStargazers.length,
|
|
590
|
+
},
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
const events = await this.syncContent({
|
|
595
|
+
repo,
|
|
596
|
+
contentType,
|
|
597
|
+
sinceIso,
|
|
598
|
+
labelsFilter: config.labels_filter ?? [],
|
|
599
|
+
token,
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
return {
|
|
603
|
+
events,
|
|
604
|
+
checkpoint: {
|
|
605
|
+
last_sync_at: new Date().toISOString(),
|
|
606
|
+
} as Record<string, unknown>,
|
|
607
|
+
metadata: {
|
|
608
|
+
items_found: events.length,
|
|
609
|
+
},
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
async execute(ctx: ActionContext): Promise<ActionResult> {
|
|
614
|
+
try {
|
|
615
|
+
const config = ctx.config as GitHubConfig;
|
|
616
|
+
const repo = this.resolveRepo(config, ctx.input);
|
|
617
|
+
const token = this.resolveToken(ctx.credentials?.accessToken, config);
|
|
618
|
+
|
|
619
|
+
if (!token) {
|
|
620
|
+
return { success: false, error: 'GitHub action requires OAuth or GITHUB_TOKEN.' };
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
switch (ctx.actionKey) {
|
|
624
|
+
case 'create_issue':
|
|
625
|
+
return await this.createIssue(repo, token, ctx.input);
|
|
626
|
+
case 'add_issue_comment':
|
|
627
|
+
return await this.addIssueComment(repo, token, ctx.input);
|
|
628
|
+
case 'close_issue':
|
|
629
|
+
return await this.updateIssueState(repo, token, ctx.input, 'closed');
|
|
630
|
+
case 'reopen_issue':
|
|
631
|
+
return await this.updateIssueState(repo, token, ctx.input, 'open');
|
|
632
|
+
case 'create_pull_request':
|
|
633
|
+
return await this.createPullRequest(repo, token, ctx.input);
|
|
634
|
+
case 'merge_pull_request':
|
|
635
|
+
return await this.mergePullRequest(repo, token, ctx.input);
|
|
636
|
+
default:
|
|
637
|
+
return { success: false, error: `Unknown action: ${ctx.actionKey}` };
|
|
638
|
+
}
|
|
639
|
+
} catch (error) {
|
|
640
|
+
return {
|
|
641
|
+
success: false,
|
|
642
|
+
error: error instanceof Error ? error.message : String(error),
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
private resolveRepo(config: GitHubConfig, input: Record<string, unknown>): RepoRef {
|
|
648
|
+
const owner = asString(input.repo_owner) ?? config.repo_owner;
|
|
649
|
+
const repo = asString(input.repo_name) ?? config.repo_name;
|
|
650
|
+
|
|
651
|
+
if (!owner || !repo) {
|
|
652
|
+
throw new Error(
|
|
653
|
+
'Repository is not configured. Provide repo_owner/repo_name in connection config or action input.'
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
return { owner, repo };
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
private resolveToken(oauthToken: string | undefined, config: GitHubConfig): string | null {
|
|
661
|
+
if (oauthToken && oauthToken.trim().length > 0) {
|
|
662
|
+
return oauthToken;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const envOverrides = config.env_overrides ?? {};
|
|
666
|
+
const configuredToken =
|
|
667
|
+
asString(envOverrides.GITHUB_TOKEN) ??
|
|
668
|
+
asString((config as Record<string, unknown>).GITHUB_TOKEN) ??
|
|
669
|
+
asString((config as Record<string, unknown>).github_token);
|
|
670
|
+
|
|
671
|
+
return configuredToken ?? null;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
private resolveSince(checkpoint: Record<string, unknown> | null, lookbackDays: number): string {
|
|
675
|
+
const cp = (checkpoint ?? {}) as GitHubCheckpoint;
|
|
676
|
+
const fromCheckpoint = toIsoOrUndefined(cp.last_sync_at);
|
|
677
|
+
if (fromCheckpoint) return fromCheckpoint;
|
|
678
|
+
|
|
679
|
+
const fallback = new Date();
|
|
680
|
+
fallback.setDate(fallback.getDate() - lookbackDays);
|
|
681
|
+
return fallback.toISOString();
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
private async syncContent(params: {
|
|
685
|
+
repo: RepoRef;
|
|
686
|
+
contentType: Exclude<GitHubContentType, 'stargazers'>;
|
|
687
|
+
sinceIso: string;
|
|
688
|
+
labelsFilter: string[];
|
|
689
|
+
token: string | null;
|
|
690
|
+
}): Promise<EventEnvelope[]> {
|
|
691
|
+
const { repo, contentType, sinceIso, labelsFilter, token } = params;
|
|
692
|
+
|
|
693
|
+
switch (contentType) {
|
|
694
|
+
case 'issues':
|
|
695
|
+
case 'pull_requests':
|
|
696
|
+
return await this.syncIssuesAndPulls(repo, contentType, sinceIso, labelsFilter, token);
|
|
697
|
+
case 'issue_comments':
|
|
698
|
+
return await this.syncIssueComments(repo, sinceIso, token);
|
|
699
|
+
case 'pr_comments':
|
|
700
|
+
return await this.syncPullRequestComments(repo, sinceIso, token);
|
|
701
|
+
case 'discussions':
|
|
702
|
+
return await this.syncDiscussions(repo, sinceIso, token);
|
|
703
|
+
case 'discussion_comments':
|
|
704
|
+
return await this.syncDiscussionComments(repo, sinceIso, token);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
private async syncIssuesAndPulls(
|
|
709
|
+
repo: RepoRef,
|
|
710
|
+
contentType: 'issues' | 'pull_requests',
|
|
711
|
+
sinceIso: string,
|
|
712
|
+
labelsFilter: string[],
|
|
713
|
+
token: string | null
|
|
714
|
+
): Promise<EventEnvelope[]> {
|
|
715
|
+
const query = new URLSearchParams({
|
|
716
|
+
state: 'all',
|
|
717
|
+
per_page: '100',
|
|
718
|
+
sort: 'updated',
|
|
719
|
+
direction: 'desc',
|
|
720
|
+
since: sinceIso,
|
|
721
|
+
});
|
|
722
|
+
if (labelsFilter.length > 0) {
|
|
723
|
+
query.set('labels', labelsFilter.join(','));
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
const url = `https://api.github.com/repos/${repo.owner}/${repo.repo}/issues?${query.toString()}`;
|
|
727
|
+
const items = await this.requestJson<GitHubIssueLike[]>({ url, token });
|
|
728
|
+
const events: EventEnvelope[] = [];
|
|
729
|
+
|
|
730
|
+
for (const item of items) {
|
|
731
|
+
const isPR = !!item.pull_request;
|
|
732
|
+
if (contentType === 'issues' && isPR) continue;
|
|
733
|
+
if (contentType === 'pull_requests' && !isPR) continue;
|
|
734
|
+
|
|
735
|
+
const createdAt = new Date(item.created_at);
|
|
736
|
+
if (Number.isNaN(createdAt.getTime())) continue;
|
|
737
|
+
|
|
738
|
+
const score = toInt(item.reactions?.total_count, 0) + toInt(item.comments, 0);
|
|
739
|
+
const labels = Array.isArray(item.labels)
|
|
740
|
+
? item.labels.map((label) => label.name).filter((v): v is string => !!v)
|
|
741
|
+
: [];
|
|
742
|
+
|
|
743
|
+
events.push({
|
|
744
|
+
origin_id: `${isPR ? 'pr' : 'issue'}_${repo.owner}_${repo.repo}_${item.number}`,
|
|
745
|
+
title: item.title,
|
|
746
|
+
payload_text: (item.body ?? '').trim(),
|
|
747
|
+
author_name: item.user?.login,
|
|
748
|
+
source_url: item.html_url,
|
|
749
|
+
occurred_at: createdAt,
|
|
750
|
+
origin_type: isPR ? 'pull_request' : 'issue',
|
|
751
|
+
score,
|
|
752
|
+
metadata: {
|
|
753
|
+
number: item.number,
|
|
754
|
+
state: item.state,
|
|
755
|
+
labels,
|
|
756
|
+
updated_at: item.updated_at,
|
|
757
|
+
reactions: item.reactions ?? {},
|
|
758
|
+
comments: item.comments ?? 0,
|
|
759
|
+
},
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
return events;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
private async syncIssueComments(
|
|
767
|
+
repo: RepoRef,
|
|
768
|
+
sinceIso: string,
|
|
769
|
+
token: string | null
|
|
770
|
+
): Promise<EventEnvelope[]> {
|
|
771
|
+
const query = new URLSearchParams({
|
|
772
|
+
per_page: '100',
|
|
773
|
+
sort: 'updated',
|
|
774
|
+
direction: 'desc',
|
|
775
|
+
since: sinceIso,
|
|
776
|
+
});
|
|
777
|
+
const url = `https://api.github.com/repos/${repo.owner}/${repo.repo}/issues/comments?${query.toString()}`;
|
|
778
|
+
const comments = await this.requestJson<GitHubCommentLike[]>({ url, token });
|
|
779
|
+
|
|
780
|
+
return comments
|
|
781
|
+
.map((comment): EventEnvelope | null => {
|
|
782
|
+
const createdAt = new Date(comment.created_at);
|
|
783
|
+
if (Number.isNaN(createdAt.getTime())) return null;
|
|
784
|
+
if (!comment.body) return null;
|
|
785
|
+
|
|
786
|
+
const issueNumber = comment.issue_url?.match(/\/issues\/(\d+)$/)?.[1];
|
|
787
|
+
return {
|
|
788
|
+
origin_id: `issue_comment_${repo.owner}_${repo.repo}_${comment.id}`,
|
|
789
|
+
payload_text: comment.body,
|
|
790
|
+
author_name: comment.user?.login,
|
|
791
|
+
source_url: comment.html_url,
|
|
792
|
+
occurred_at: createdAt,
|
|
793
|
+
origin_type: 'issue_comment',
|
|
794
|
+
score: toInt(comment.reactions?.total_count, 0),
|
|
795
|
+
origin_parent_id: issueNumber
|
|
796
|
+
? `issue_${repo.owner}_${repo.repo}_${issueNumber}`
|
|
797
|
+
: undefined,
|
|
798
|
+
metadata: {
|
|
799
|
+
updated_at: comment.updated_at,
|
|
800
|
+
reactions: comment.reactions ?? {},
|
|
801
|
+
},
|
|
802
|
+
};
|
|
803
|
+
})
|
|
804
|
+
.filter((value): value is EventEnvelope => value !== null);
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
private async syncPullRequestComments(
|
|
808
|
+
repo: RepoRef,
|
|
809
|
+
sinceIso: string,
|
|
810
|
+
token: string | null
|
|
811
|
+
): Promise<EventEnvelope[]> {
|
|
812
|
+
const query = new URLSearchParams({
|
|
813
|
+
per_page: '100',
|
|
814
|
+
sort: 'updated',
|
|
815
|
+
direction: 'desc',
|
|
816
|
+
since: sinceIso,
|
|
817
|
+
});
|
|
818
|
+
const url = `https://api.github.com/repos/${repo.owner}/${repo.repo}/pulls/comments?${query.toString()}`;
|
|
819
|
+
const comments = await this.requestJson<GitHubCommentLike[]>({ url, token });
|
|
820
|
+
|
|
821
|
+
return comments
|
|
822
|
+
.map((comment): EventEnvelope | null => {
|
|
823
|
+
const createdAt = new Date(comment.created_at);
|
|
824
|
+
if (Number.isNaN(createdAt.getTime())) return null;
|
|
825
|
+
if (!comment.body) return null;
|
|
826
|
+
|
|
827
|
+
const prNumber = comment.pull_request_url?.match(/\/pulls\/(\d+)$/)?.[1];
|
|
828
|
+
return {
|
|
829
|
+
origin_id: `pr_comment_${repo.owner}_${repo.repo}_${comment.id}`,
|
|
830
|
+
payload_text: comment.body,
|
|
831
|
+
author_name: comment.user?.login,
|
|
832
|
+
source_url: comment.html_url,
|
|
833
|
+
occurred_at: createdAt,
|
|
834
|
+
origin_type: 'pr_comment',
|
|
835
|
+
score: toInt(comment.reactions?.total_count, 0),
|
|
836
|
+
origin_parent_id: prNumber ? `pr_${repo.owner}_${repo.repo}_${prNumber}` : undefined,
|
|
837
|
+
metadata: {
|
|
838
|
+
updated_at: comment.updated_at,
|
|
839
|
+
reactions: comment.reactions ?? {},
|
|
840
|
+
},
|
|
841
|
+
};
|
|
842
|
+
})
|
|
843
|
+
.filter((value): value is EventEnvelope => value !== null);
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
private async syncDiscussions(
|
|
847
|
+
repo: RepoRef,
|
|
848
|
+
sinceIso: string,
|
|
849
|
+
token: string | null
|
|
850
|
+
): Promise<EventEnvelope[]> {
|
|
851
|
+
const query = `
|
|
852
|
+
query($owner: String!, $repo: String!) {
|
|
853
|
+
repository(owner: $owner, name: $repo) {
|
|
854
|
+
discussions(first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
|
855
|
+
nodes {
|
|
856
|
+
id
|
|
857
|
+
number
|
|
858
|
+
title
|
|
859
|
+
body
|
|
860
|
+
author { login }
|
|
861
|
+
url
|
|
862
|
+
createdAt
|
|
863
|
+
updatedAt
|
|
864
|
+
category { name }
|
|
865
|
+
comments { totalCount }
|
|
866
|
+
reactions { totalCount }
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
`;
|
|
872
|
+
|
|
873
|
+
const response = await this.requestGraphQL<{
|
|
874
|
+
data?: {
|
|
875
|
+
repository?: {
|
|
876
|
+
discussions?: { nodes?: GraphQLDiscussionNode[] };
|
|
877
|
+
};
|
|
878
|
+
};
|
|
879
|
+
}>({
|
|
880
|
+
token,
|
|
881
|
+
query,
|
|
882
|
+
variables: { owner: repo.owner, repo: repo.repo },
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
const discussions = response.data?.repository?.discussions?.nodes ?? [];
|
|
886
|
+
const since = new Date(sinceIso).getTime();
|
|
887
|
+
|
|
888
|
+
return discussions
|
|
889
|
+
.map((discussion): EventEnvelope | null => {
|
|
890
|
+
const createdAt = new Date(discussion.createdAt);
|
|
891
|
+
const updatedAt = new Date(discussion.updatedAt).getTime();
|
|
892
|
+
if (Number.isNaN(createdAt.getTime())) return null;
|
|
893
|
+
if (!Number.isNaN(since) && updatedAt < since) return null;
|
|
894
|
+
|
|
895
|
+
return {
|
|
896
|
+
origin_id: `discussion_${repo.owner}_${repo.repo}_${discussion.number}`,
|
|
897
|
+
title: discussion.title,
|
|
898
|
+
payload_text: (discussion.body ?? '').trim(),
|
|
899
|
+
author_name: discussion.author?.login,
|
|
900
|
+
source_url: discussion.url,
|
|
901
|
+
occurred_at: createdAt,
|
|
902
|
+
origin_type: 'discussion',
|
|
903
|
+
score:
|
|
904
|
+
toInt(discussion.reactions?.totalCount, 0) + toInt(discussion.comments?.totalCount, 0),
|
|
905
|
+
metadata: {
|
|
906
|
+
number: discussion.number,
|
|
907
|
+
category: discussion.category?.name ?? null,
|
|
908
|
+
updated_at: discussion.updatedAt,
|
|
909
|
+
comments: discussion.comments?.totalCount ?? 0,
|
|
910
|
+
reactions: discussion.reactions?.totalCount ?? 0,
|
|
911
|
+
},
|
|
912
|
+
};
|
|
913
|
+
})
|
|
914
|
+
.filter((value): value is EventEnvelope => value !== null);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
private async syncDiscussionComments(
|
|
918
|
+
repo: RepoRef,
|
|
919
|
+
sinceIso: string,
|
|
920
|
+
token: string | null
|
|
921
|
+
): Promise<EventEnvelope[]> {
|
|
922
|
+
const query = `
|
|
923
|
+
query($owner: String!, $repo: String!) {
|
|
924
|
+
repository(owner: $owner, name: $repo) {
|
|
925
|
+
discussions(first: 50, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
|
926
|
+
nodes {
|
|
927
|
+
number
|
|
928
|
+
comments(first: 50) {
|
|
929
|
+
nodes {
|
|
930
|
+
id
|
|
931
|
+
body
|
|
932
|
+
url
|
|
933
|
+
createdAt
|
|
934
|
+
updatedAt
|
|
935
|
+
author { login }
|
|
936
|
+
reactions { totalCount }
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
`;
|
|
944
|
+
|
|
945
|
+
const response = await this.requestGraphQL<{
|
|
946
|
+
data?: {
|
|
947
|
+
repository?: {
|
|
948
|
+
discussions?: {
|
|
949
|
+
nodes?: Array<{
|
|
950
|
+
number: number;
|
|
951
|
+
comments?: { nodes?: Array<Omit<GraphQLDiscussionCommentNode, 'discussion'>> };
|
|
952
|
+
}>;
|
|
953
|
+
};
|
|
954
|
+
};
|
|
955
|
+
};
|
|
956
|
+
}>({
|
|
957
|
+
token,
|
|
958
|
+
query,
|
|
959
|
+
variables: { owner: repo.owner, repo: repo.repo },
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
const discussions = response.data?.repository?.discussions?.nodes ?? [];
|
|
963
|
+
const since = new Date(sinceIso).getTime();
|
|
964
|
+
const result: EventEnvelope[] = [];
|
|
965
|
+
|
|
966
|
+
for (const discussion of discussions) {
|
|
967
|
+
const comments = discussion.comments?.nodes ?? [];
|
|
968
|
+
for (const comment of comments) {
|
|
969
|
+
const createdAt = new Date(comment.createdAt);
|
|
970
|
+
const updatedAt = new Date(comment.updatedAt).getTime();
|
|
971
|
+
if (Number.isNaN(createdAt.getTime())) continue;
|
|
972
|
+
if (!Number.isNaN(since) && updatedAt < since) continue;
|
|
973
|
+
if (!comment.body?.trim()) continue;
|
|
974
|
+
|
|
975
|
+
result.push({
|
|
976
|
+
origin_id: `discussion_comment_${repo.owner}_${repo.repo}_${comment.id}`,
|
|
977
|
+
payload_text: comment.body.trim(),
|
|
978
|
+
author_name: comment.author?.login,
|
|
979
|
+
source_url: comment.url,
|
|
980
|
+
occurred_at: createdAt,
|
|
981
|
+
origin_type: 'discussion_comment',
|
|
982
|
+
score: toInt(comment.reactions?.totalCount, 0),
|
|
983
|
+
origin_parent_id: `discussion_${repo.owner}_${repo.repo}_${discussion.number}`,
|
|
984
|
+
metadata: {
|
|
985
|
+
discussion_number: discussion.number,
|
|
986
|
+
updated_at: comment.updatedAt,
|
|
987
|
+
reactions: comment.reactions?.totalCount ?? 0,
|
|
988
|
+
},
|
|
989
|
+
});
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
return result;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
private async syncStargazers(
|
|
997
|
+
repo: RepoRef,
|
|
998
|
+
checkpoint: Record<string, unknown> | null,
|
|
999
|
+
token: string | null
|
|
1000
|
+
): Promise<{ events: EventEnvelope[]; currentStargazers: GitHubStargazerCheckpoint[] }> {
|
|
1001
|
+
const previous = this.parseStargazerCheckpoint(checkpoint);
|
|
1002
|
+
const previousByKey = new Map(previous.map((stargazer) => [stargazer.key, stargazer]));
|
|
1003
|
+
const currentStargazers: GitHubStargazerCheckpoint[] = [];
|
|
1004
|
+
const events: EventEnvelope[] = [];
|
|
1005
|
+
const now = new Date();
|
|
1006
|
+
const repoInfo = await this.fetchRepository(repo, token);
|
|
1007
|
+
const target = this.buildRepoTarget(repo, repoInfo);
|
|
1008
|
+
let remainingProfileFetches = STARGAZER_PROFILE_FETCH_LIMIT;
|
|
1009
|
+
|
|
1010
|
+
for (let page = 1; ; page += 1) {
|
|
1011
|
+
const query = new URLSearchParams({
|
|
1012
|
+
per_page: '100',
|
|
1013
|
+
page: String(page),
|
|
1014
|
+
});
|
|
1015
|
+
const url = `https://api.github.com/repos/${repo.owner}/${repo.repo}/stargazers?${query.toString()}`;
|
|
1016
|
+
const stargazers = await this.requestJson<GitHubStargazerLike[]>({
|
|
1017
|
+
url,
|
|
1018
|
+
token,
|
|
1019
|
+
accept: 'application/vnd.github.star+json',
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
if (stargazers.length === 0) break;
|
|
1023
|
+
|
|
1024
|
+
for (const stargazer of stargazers) {
|
|
1025
|
+
const user = stargazer.user ?? stargazer;
|
|
1026
|
+
const login = user.login;
|
|
1027
|
+
if (!login) continue;
|
|
1028
|
+
|
|
1029
|
+
const key = this.githubUserKey(user, login);
|
|
1030
|
+
const starredAtIso = toIsoOrUndefined(stargazer.starred_at) ?? now.toISOString();
|
|
1031
|
+
const starredAt = new Date(starredAtIso);
|
|
1032
|
+
if (Number.isNaN(starredAt.getTime())) continue;
|
|
1033
|
+
|
|
1034
|
+
const previousStargazer = previousByKey.get(key);
|
|
1035
|
+
const shouldRefreshProfile = this.shouldRefreshStargazerProfile(previousStargazer, now);
|
|
1036
|
+
const profileFetchedAt = shouldRefreshProfile && remainingProfileFetches > 0
|
|
1037
|
+
? await this.enqueueStargazerProfileEvent({
|
|
1038
|
+
events,
|
|
1039
|
+
login,
|
|
1040
|
+
token,
|
|
1041
|
+
fallback: user,
|
|
1042
|
+
fetchedAt: now,
|
|
1043
|
+
})
|
|
1044
|
+
: (previousStargazer?.profile_fetched_at ?? null);
|
|
1045
|
+
if (shouldRefreshProfile && remainingProfileFetches > 0) remainingProfileFetches -= 1;
|
|
1046
|
+
|
|
1047
|
+
currentStargazers.push({
|
|
1048
|
+
key,
|
|
1049
|
+
login,
|
|
1050
|
+
starred_at: starredAt.toISOString(),
|
|
1051
|
+
user_id: user.id ?? previousStargazer?.user_id ?? null,
|
|
1052
|
+
user_type: user.type ?? previousStargazer?.user_type ?? null,
|
|
1053
|
+
html_url: user.html_url ?? previousStargazer?.html_url ?? `https://github.com/${login}`,
|
|
1054
|
+
profile_fetched_at: profileFetchedAt,
|
|
1055
|
+
});
|
|
1056
|
+
|
|
1057
|
+
if (!previousStargazer) {
|
|
1058
|
+
events.push({
|
|
1059
|
+
origin_id: `stargazer_${repo.owner}_${repo.repo}_${this.keyForOriginId(key)}`,
|
|
1060
|
+
title: `${login} starred ${repo.owner}/${repo.repo}`,
|
|
1061
|
+
payload_text: `${login} starred ${repo.owner}/${repo.repo}.`,
|
|
1062
|
+
author_name: login,
|
|
1063
|
+
source_url: user.html_url ?? `https://github.com/${login}`,
|
|
1064
|
+
occurred_at: starredAt,
|
|
1065
|
+
origin_type: 'stargazer',
|
|
1066
|
+
score: 1,
|
|
1067
|
+
metadata: {
|
|
1068
|
+
actor: this.buildActor(user, login),
|
|
1069
|
+
target,
|
|
1070
|
+
action: 'starred',
|
|
1071
|
+
starred_at: starredAt.toISOString(),
|
|
1072
|
+
source: 'github_stargazers_snapshot',
|
|
1073
|
+
},
|
|
1074
|
+
});
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
if (stargazers.length < 100) break;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const currentKeys = new Set(currentStargazers.map((stargazer) => stargazer.key));
|
|
1082
|
+
for (const previousStargazer of previous) {
|
|
1083
|
+
if (currentKeys.has(previousStargazer.key)) continue;
|
|
1084
|
+
|
|
1085
|
+
events.push({
|
|
1086
|
+
origin_id: `stargazer_unstarred_${repo.owner}_${repo.repo}_${this.keyForOriginId(previousStargazer.key)}_${now.getTime()}`,
|
|
1087
|
+
title: `${previousStargazer.login} unstarred ${repo.owner}/${repo.repo}`,
|
|
1088
|
+
payload_text: `${previousStargazer.login} unstarred ${repo.owner}/${repo.repo}.`,
|
|
1089
|
+
author_name: previousStargazer.login,
|
|
1090
|
+
source_url: previousStargazer.html_url ?? `https://github.com/${previousStargazer.login}`,
|
|
1091
|
+
occurred_at: now,
|
|
1092
|
+
origin_type: 'stargazer_unstarred',
|
|
1093
|
+
score: 1,
|
|
1094
|
+
metadata: {
|
|
1095
|
+
actor: this.buildActorFromCheckpoint(previousStargazer),
|
|
1096
|
+
target,
|
|
1097
|
+
action: 'unstarred',
|
|
1098
|
+
starred_at: previousStargazer.starred_at ?? null,
|
|
1099
|
+
unstarred_at: now.toISOString(),
|
|
1100
|
+
unstarred_at_is_inferred: true,
|
|
1101
|
+
source: 'github_stargazers_snapshot_diff',
|
|
1102
|
+
},
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
return { events, currentStargazers };
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
private shouldRefreshStargazerProfile(
|
|
1110
|
+
previous: GitHubStargazerCheckpoint | undefined,
|
|
1111
|
+
now: Date
|
|
1112
|
+
): boolean {
|
|
1113
|
+
const fetchedAt = toIsoOrUndefined(previous?.profile_fetched_at);
|
|
1114
|
+
if (!fetchedAt) return true;
|
|
1115
|
+
return now.getTime() - new Date(fetchedAt).getTime() >= STARGAZER_PROFILE_REFRESH_MS;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
private async enqueueStargazerProfileEvent(params: {
|
|
1119
|
+
events: EventEnvelope[];
|
|
1120
|
+
login: string;
|
|
1121
|
+
token: string | null;
|
|
1122
|
+
fallback: GitHubStargazerLike['user'] | GitHubStargazerLike;
|
|
1123
|
+
fetchedAt: Date;
|
|
1124
|
+
}): Promise<string> {
|
|
1125
|
+
const profile = await this.fetchUserProfile(params.login, params.token, params.fallback);
|
|
1126
|
+
const profileUrl = profile.html_url ?? `https://github.com/${params.login}`;
|
|
1127
|
+
const occurredAt = new Date(
|
|
1128
|
+
toIsoOrUndefined(profile.updated_at) ?? params.fetchedAt.toISOString()
|
|
1129
|
+
);
|
|
1130
|
+
const identities = this.githubUserIdentities(profile, params.login);
|
|
1131
|
+
|
|
1132
|
+
params.events.push({
|
|
1133
|
+
origin_id: `stargazer_profile_${this.keyForOriginId(this.githubUserKey(profile, params.login))}`,
|
|
1134
|
+
title: profile.name || params.login,
|
|
1135
|
+
payload_text: profile.bio || `GitHub profile for ${params.login}.`,
|
|
1136
|
+
author_name: params.login,
|
|
1137
|
+
source_url: profileUrl,
|
|
1138
|
+
occurred_at: Number.isNaN(occurredAt.getTime()) ? params.fetchedAt : occurredAt,
|
|
1139
|
+
origin_type: 'stargazer_profile',
|
|
1140
|
+
score: toInt(profile.followers, 0),
|
|
1141
|
+
metadata: {
|
|
1142
|
+
public_identity_profile: true,
|
|
1143
|
+
provider: 'github',
|
|
1144
|
+
identities,
|
|
1145
|
+
account: {
|
|
1146
|
+
provider: 'github',
|
|
1147
|
+
provider_user_id: profile.id ? String(profile.id) : null,
|
|
1148
|
+
handle: params.login,
|
|
1149
|
+
url: profileUrl,
|
|
1150
|
+
avatar_url: profile.avatar_url ?? null,
|
|
1151
|
+
user_type: profile.type ?? null,
|
|
1152
|
+
site_admin: profile.site_admin ?? false,
|
|
1153
|
+
profile: {
|
|
1154
|
+
name: profile.name ?? null,
|
|
1155
|
+
company: profile.company ?? null,
|
|
1156
|
+
blog: profile.blog ?? null,
|
|
1157
|
+
location: profile.location ?? null,
|
|
1158
|
+
email: profile.email ?? null,
|
|
1159
|
+
bio: profile.bio ?? null,
|
|
1160
|
+
twitter_username: profile.twitter_username ?? null,
|
|
1161
|
+
public_repos: profile.public_repos ?? null,
|
|
1162
|
+
public_gists: profile.public_gists ?? null,
|
|
1163
|
+
followers: profile.followers ?? null,
|
|
1164
|
+
following: profile.following ?? null,
|
|
1165
|
+
github_created_at: profile.created_at ?? null,
|
|
1166
|
+
github_updated_at: profile.updated_at ?? null,
|
|
1167
|
+
},
|
|
1168
|
+
fetched_at: params.fetchedAt.toISOString(),
|
|
1169
|
+
},
|
|
1170
|
+
},
|
|
1171
|
+
});
|
|
1172
|
+
|
|
1173
|
+
return params.fetchedAt.toISOString();
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1176
|
+
private async fetchUserProfile(
|
|
1177
|
+
login: string,
|
|
1178
|
+
token: string | null,
|
|
1179
|
+
fallback: GitHubStargazerLike['user'] | GitHubStargazerLike
|
|
1180
|
+
): Promise<GitHubUserProfile> {
|
|
1181
|
+
try {
|
|
1182
|
+
return await this.requestJson<GitHubUserProfile>({
|
|
1183
|
+
url: `https://api.github.com/users/${encodeURIComponent(login)}`,
|
|
1184
|
+
token,
|
|
1185
|
+
});
|
|
1186
|
+
} catch {
|
|
1187
|
+
return {
|
|
1188
|
+
id: fallback?.id,
|
|
1189
|
+
login,
|
|
1190
|
+
html_url: fallback?.html_url ?? `https://github.com/${login}`,
|
|
1191
|
+
avatar_url: fallback?.avatar_url,
|
|
1192
|
+
type: fallback?.type,
|
|
1193
|
+
site_admin: fallback?.site_admin,
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
private async fetchRepository(
|
|
1199
|
+
repo: RepoRef,
|
|
1200
|
+
token: string | null
|
|
1201
|
+
): Promise<GitHubRepositoryLike> {
|
|
1202
|
+
try {
|
|
1203
|
+
return await this.requestJson<GitHubRepositoryLike>({
|
|
1204
|
+
url: `https://api.github.com/repos/${repo.owner}/${repo.repo}`,
|
|
1205
|
+
token,
|
|
1206
|
+
});
|
|
1207
|
+
} catch {
|
|
1208
|
+
return {
|
|
1209
|
+
full_name: `${repo.owner}/${repo.repo}`,
|
|
1210
|
+
html_url: `https://github.com/${repo.owner}/${repo.repo}`,
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
private githubUserKey(user: Pick<GitHubUserProfile, 'id'>, login: string): string {
|
|
1216
|
+
return user.id ? `${IDENTITY.GITHUB_USER_ID}:${user.id}` : `${IDENTITY.GITHUB_LOGIN}:${login.toLowerCase()}`;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
private keyForOriginId(key: string): string {
|
|
1220
|
+
return key.replace(/[^a-z0-9]+/gi, '_');
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
private githubUserIdentities(
|
|
1224
|
+
user: Pick<GitHubUserProfile, 'id'>,
|
|
1225
|
+
login: string
|
|
1226
|
+
): Array<{ namespace: string; identifier: string; verification_status: string }> {
|
|
1227
|
+
const identities: Array<{ namespace: string; identifier: string; verification_status: string }> = [];
|
|
1228
|
+
if (user.id) {
|
|
1229
|
+
identities.push({
|
|
1230
|
+
namespace: IDENTITY.GITHUB_USER_ID,
|
|
1231
|
+
identifier: String(user.id),
|
|
1232
|
+
verification_status: 'observed',
|
|
1233
|
+
});
|
|
1234
|
+
}
|
|
1235
|
+
identities.push({
|
|
1236
|
+
namespace: IDENTITY.GITHUB_LOGIN,
|
|
1237
|
+
identifier: login.toLowerCase(),
|
|
1238
|
+
verification_status: 'observed',
|
|
1239
|
+
});
|
|
1240
|
+
return identities;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
private buildActor(user: GitHubStargazerLike['user'] | GitHubStargazerLike, login: string) {
|
|
1244
|
+
return {
|
|
1245
|
+
provider: 'github',
|
|
1246
|
+
identity: user?.id
|
|
1247
|
+
? { namespace: IDENTITY.GITHUB_USER_ID, identifier: String(user.id) }
|
|
1248
|
+
: { namespace: IDENTITY.GITHUB_LOGIN, identifier: login.toLowerCase() },
|
|
1249
|
+
handle: { namespace: IDENTITY.GITHUB_LOGIN, identifier: login.toLowerCase() },
|
|
1250
|
+
profile_url: user?.html_url ?? `https://github.com/${login}`,
|
|
1251
|
+
user_type: user?.type ?? null,
|
|
1252
|
+
};
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
private buildActorFromCheckpoint(stargazer: GitHubStargazerCheckpoint) {
|
|
1256
|
+
const [namespace, ...identifierParts] = stargazer.key.split(':');
|
|
1257
|
+
const identifier = identifierParts.join(':');
|
|
1258
|
+
return {
|
|
1259
|
+
provider: 'github',
|
|
1260
|
+
identity: { namespace, identifier },
|
|
1261
|
+
handle: { namespace: IDENTITY.GITHUB_LOGIN, identifier: stargazer.login.toLowerCase() },
|
|
1262
|
+
profile_url: stargazer.html_url ?? `https://github.com/${stargazer.login}`,
|
|
1263
|
+
user_type: stargazer.user_type ?? null,
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
private buildRepoTarget(repo: RepoRef, repoInfo: GitHubRepositoryLike) {
|
|
1268
|
+
const fullName = (repoInfo.full_name ?? `${repo.owner}/${repo.repo}`).toLowerCase();
|
|
1269
|
+
return {
|
|
1270
|
+
provider: 'github',
|
|
1271
|
+
identity: repoInfo.id
|
|
1272
|
+
? { namespace: IDENTITY.GITHUB_REPO_ID, identifier: String(repoInfo.id) }
|
|
1273
|
+
: { namespace: IDENTITY.GITHUB_REPO_FULL_NAME, identifier: fullName },
|
|
1274
|
+
handle: { namespace: IDENTITY.GITHUB_REPO_FULL_NAME, identifier: fullName },
|
|
1275
|
+
url: repoInfo.html_url ?? `https://github.com/${repo.owner}/${repo.repo}`,
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
private parseStargazerCheckpoint(
|
|
1280
|
+
checkpoint: Record<string, unknown> | null
|
|
1281
|
+
): GitHubStargazerCheckpoint[] {
|
|
1282
|
+
const raw = (checkpoint as GitHubCheckpoint | null)?.stargazers;
|
|
1283
|
+
if (!Array.isArray(raw)) return [];
|
|
1284
|
+
|
|
1285
|
+
return raw
|
|
1286
|
+
.map((item): GitHubStargazerCheckpoint | null => {
|
|
1287
|
+
if (!item || typeof item !== 'object') return null;
|
|
1288
|
+
const value = item as Record<string, unknown>;
|
|
1289
|
+
const login = asString(value.login);
|
|
1290
|
+
if (!login) return null;
|
|
1291
|
+
const userId = typeof value.user_id === 'number' ? value.user_id : null;
|
|
1292
|
+
const key = asString(value.key) ?? (userId ? `${IDENTITY.GITHUB_USER_ID}:${userId}` : `${IDENTITY.GITHUB_LOGIN}:${login.toLowerCase()}`);
|
|
1293
|
+
|
|
1294
|
+
return {
|
|
1295
|
+
key,
|
|
1296
|
+
login,
|
|
1297
|
+
starred_at: asString(value.starred_at),
|
|
1298
|
+
user_id: userId,
|
|
1299
|
+
user_type: asString(value.user_type) ?? null,
|
|
1300
|
+
html_url: asString(value.html_url) ?? null,
|
|
1301
|
+
profile_fetched_at: asString(value.profile_fetched_at) ?? null,
|
|
1302
|
+
};
|
|
1303
|
+
})
|
|
1304
|
+
.filter((value): value is GitHubStargazerCheckpoint => value !== null);
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
private async createIssue(
|
|
1308
|
+
repo: RepoRef,
|
|
1309
|
+
token: string,
|
|
1310
|
+
input: Record<string, unknown>
|
|
1311
|
+
): Promise<ActionResult> {
|
|
1312
|
+
const title = asString(input.title);
|
|
1313
|
+
if (!title) return { success: false, error: 'title is required' };
|
|
1314
|
+
|
|
1315
|
+
const body = asString(input.body);
|
|
1316
|
+
const labels = Array.isArray(input.labels)
|
|
1317
|
+
? input.labels.filter((value): value is string => typeof value === 'string')
|
|
1318
|
+
: undefined;
|
|
1319
|
+
const assignees = Array.isArray(input.assignees)
|
|
1320
|
+
? input.assignees.filter((value): value is string => typeof value === 'string')
|
|
1321
|
+
: undefined;
|
|
1322
|
+
|
|
1323
|
+
const issue = await this.requestJson<GitHubMutationResponse>({
|
|
1324
|
+
method: 'POST',
|
|
1325
|
+
url: `https://api.github.com/repos/${repo.owner}/${repo.repo}/issues`,
|
|
1326
|
+
token,
|
|
1327
|
+
body: {
|
|
1328
|
+
title,
|
|
1329
|
+
body,
|
|
1330
|
+
labels,
|
|
1331
|
+
assignees,
|
|
1332
|
+
},
|
|
1333
|
+
});
|
|
1334
|
+
|
|
1335
|
+
return {
|
|
1336
|
+
success: true,
|
|
1337
|
+
output: {
|
|
1338
|
+
issue_id: issue.id,
|
|
1339
|
+
issue_number: issue.number,
|
|
1340
|
+
url: issue.html_url,
|
|
1341
|
+
state: issue.state,
|
|
1342
|
+
},
|
|
1343
|
+
};
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
private async addIssueComment(
|
|
1347
|
+
repo: RepoRef,
|
|
1348
|
+
token: string,
|
|
1349
|
+
input: Record<string, unknown>
|
|
1350
|
+
): Promise<ActionResult> {
|
|
1351
|
+
const issueNumber = toInt(input.issue_number, 0);
|
|
1352
|
+
const body = asString(input.body);
|
|
1353
|
+
if (!issueNumber) return { success: false, error: 'issue_number is required' };
|
|
1354
|
+
if (!body) return { success: false, error: 'body is required' };
|
|
1355
|
+
|
|
1356
|
+
const comment = await this.requestJson<{
|
|
1357
|
+
id: number;
|
|
1358
|
+
html_url: string;
|
|
1359
|
+
}>({
|
|
1360
|
+
method: 'POST',
|
|
1361
|
+
url: `https://api.github.com/repos/${repo.owner}/${repo.repo}/issues/${issueNumber}/comments`,
|
|
1362
|
+
token,
|
|
1363
|
+
body: { body },
|
|
1364
|
+
});
|
|
1365
|
+
|
|
1366
|
+
return {
|
|
1367
|
+
success: true,
|
|
1368
|
+
output: {
|
|
1369
|
+
comment_id: comment.id,
|
|
1370
|
+
issue_number: issueNumber,
|
|
1371
|
+
url: comment.html_url,
|
|
1372
|
+
},
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
private async updateIssueState(
|
|
1377
|
+
repo: RepoRef,
|
|
1378
|
+
token: string,
|
|
1379
|
+
input: Record<string, unknown>,
|
|
1380
|
+
state: 'open' | 'closed'
|
|
1381
|
+
): Promise<ActionResult> {
|
|
1382
|
+
const issueNumber = toInt(input.issue_number, 0);
|
|
1383
|
+
if (!issueNumber) return { success: false, error: 'issue_number is required' };
|
|
1384
|
+
|
|
1385
|
+
const issue = await this.requestJson<GitHubMutationResponse>({
|
|
1386
|
+
method: 'PATCH',
|
|
1387
|
+
url: `https://api.github.com/repos/${repo.owner}/${repo.repo}/issues/${issueNumber}`,
|
|
1388
|
+
token,
|
|
1389
|
+
body: { state },
|
|
1390
|
+
});
|
|
1391
|
+
|
|
1392
|
+
return {
|
|
1393
|
+
success: true,
|
|
1394
|
+
output: {
|
|
1395
|
+
issue_id: issue.id,
|
|
1396
|
+
issue_number: issue.number,
|
|
1397
|
+
url: issue.html_url,
|
|
1398
|
+
state: issue.state,
|
|
1399
|
+
},
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
private async createPullRequest(
|
|
1404
|
+
repo: RepoRef,
|
|
1405
|
+
token: string,
|
|
1406
|
+
input: Record<string, unknown>
|
|
1407
|
+
): Promise<ActionResult> {
|
|
1408
|
+
const title = asString(input.title);
|
|
1409
|
+
const head = asString(input.head);
|
|
1410
|
+
const base = asString(input.base);
|
|
1411
|
+
if (!title) return { success: false, error: 'title is required' };
|
|
1412
|
+
if (!head) return { success: false, error: 'head is required' };
|
|
1413
|
+
if (!base) return { success: false, error: 'base is required' };
|
|
1414
|
+
|
|
1415
|
+
const body = asString(input.body);
|
|
1416
|
+
const draft = typeof input.draft === 'boolean' ? input.draft : undefined;
|
|
1417
|
+
|
|
1418
|
+
const pr = await this.requestJson<GitHubMutationResponse>({
|
|
1419
|
+
method: 'POST',
|
|
1420
|
+
url: `https://api.github.com/repos/${repo.owner}/${repo.repo}/pulls`,
|
|
1421
|
+
token,
|
|
1422
|
+
body: {
|
|
1423
|
+
title,
|
|
1424
|
+
head,
|
|
1425
|
+
base,
|
|
1426
|
+
body,
|
|
1427
|
+
draft,
|
|
1428
|
+
},
|
|
1429
|
+
});
|
|
1430
|
+
|
|
1431
|
+
return {
|
|
1432
|
+
success: true,
|
|
1433
|
+
output: {
|
|
1434
|
+
pull_request_id: pr.id,
|
|
1435
|
+
pull_number: pr.number,
|
|
1436
|
+
url: pr.html_url,
|
|
1437
|
+
state: pr.state,
|
|
1438
|
+
draft: pr.draft ?? false,
|
|
1439
|
+
},
|
|
1440
|
+
};
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
private async mergePullRequest(
|
|
1444
|
+
repo: RepoRef,
|
|
1445
|
+
token: string,
|
|
1446
|
+
input: Record<string, unknown>
|
|
1447
|
+
): Promise<ActionResult> {
|
|
1448
|
+
const pullNumber = toInt(input.pull_number, 0);
|
|
1449
|
+
if (!pullNumber) return { success: false, error: 'pull_number is required' };
|
|
1450
|
+
|
|
1451
|
+
const mergeMethod = asString(input.merge_method);
|
|
1452
|
+
const commitTitle = asString(input.commit_title);
|
|
1453
|
+
const commitMessage = asString(input.commit_message);
|
|
1454
|
+
|
|
1455
|
+
const merged = await this.requestJson<{
|
|
1456
|
+
sha: string;
|
|
1457
|
+
merged: boolean;
|
|
1458
|
+
message: string;
|
|
1459
|
+
}>({
|
|
1460
|
+
method: 'PUT',
|
|
1461
|
+
url: `https://api.github.com/repos/${repo.owner}/${repo.repo}/pulls/${pullNumber}/merge`,
|
|
1462
|
+
token,
|
|
1463
|
+
body: {
|
|
1464
|
+
merge_method:
|
|
1465
|
+
mergeMethod === 'merge' || mergeMethod === 'squash' || mergeMethod === 'rebase'
|
|
1466
|
+
? mergeMethod
|
|
1467
|
+
: undefined,
|
|
1468
|
+
commit_title: commitTitle,
|
|
1469
|
+
commit_message: commitMessage,
|
|
1470
|
+
},
|
|
1471
|
+
});
|
|
1472
|
+
|
|
1473
|
+
return {
|
|
1474
|
+
success: true,
|
|
1475
|
+
output: {
|
|
1476
|
+
pull_number: pullNumber,
|
|
1477
|
+
merged: !!merged.merged,
|
|
1478
|
+
message: merged.message,
|
|
1479
|
+
sha: merged.sha,
|
|
1480
|
+
},
|
|
1481
|
+
};
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
private async requestGraphQL<T>(params: {
|
|
1485
|
+
token: string | null;
|
|
1486
|
+
query: string;
|
|
1487
|
+
variables?: Record<string, unknown>;
|
|
1488
|
+
}): Promise<T> {
|
|
1489
|
+
return await this.requestJson<T>({
|
|
1490
|
+
method: 'POST',
|
|
1491
|
+
url: 'https://api.github.com/graphql',
|
|
1492
|
+
token: params.token,
|
|
1493
|
+
body: {
|
|
1494
|
+
query: params.query,
|
|
1495
|
+
variables: params.variables ?? {},
|
|
1496
|
+
},
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
private async requestJson<T>(params: {
|
|
1501
|
+
url: string;
|
|
1502
|
+
method?: string;
|
|
1503
|
+
token: string | null;
|
|
1504
|
+
body?: Record<string, unknown>;
|
|
1505
|
+
accept?: string;
|
|
1506
|
+
}): Promise<T> {
|
|
1507
|
+
const method = params.method ?? 'GET';
|
|
1508
|
+
const headers: Record<string, string> = {
|
|
1509
|
+
Accept: params.accept ?? 'application/vnd.github+json',
|
|
1510
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
1511
|
+
'Content-Type': 'application/json',
|
|
1512
|
+
};
|
|
1513
|
+
if (params.token) {
|
|
1514
|
+
headers.Authorization = `Bearer ${params.token}`;
|
|
1515
|
+
}
|
|
1516
|
+
|
|
1517
|
+
const response = await fetch(params.url, {
|
|
1518
|
+
method,
|
|
1519
|
+
headers,
|
|
1520
|
+
body: params.body ? JSON.stringify(params.body) : undefined,
|
|
1521
|
+
});
|
|
1522
|
+
|
|
1523
|
+
if (!response.ok) {
|
|
1524
|
+
const text = await response.text();
|
|
1525
|
+
throw new Error(`GitHub API ${method} ${params.url} failed (${response.status}): ${text}`);
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
return (await response.json()) as T;
|
|
1529
|
+
}
|
|
1530
|
+
}
|