Skip to content

Commit bf9b5a6

Browse files
authored
Merge pull request #73 from codex-team/task-manager-refactoring
chore(task-manager): refactor task manager types
2 parents 18d09f1 + ea63dbb commit bf9b5a6

17 files changed

Lines changed: 353 additions & 115 deletions

.github/workflows/npm-publish.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@ jobs:
1717
- run: yarn
1818
- run: yarn lint
1919
- run: yarn build
20-
- run: yarn publish --access=public
20+
- name: Determine npm dist-tag
21+
id: dist-tag
22+
run: |
23+
VERSION=$(node -p "require('./package.json').version")
24+
if echo "$VERSION" | grep -q "\-rc\."; then
25+
echo "tag=rc" >> "$GITHUB_OUTPUT"
26+
else
27+
echo "tag=latest" >> "$GITHUB_OUTPUT"
28+
fi
29+
- run: yarn publish --access=public --tag ${{ steps.dist-tag.outputs.tag }}
2130
env:
2231
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
2332
notify:

build/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export * from './src/base/event/taskManagerItem';
1010
export * from './src/base/event/addons';
1111
export * from './src/base/integrations/integrationToken';
1212
export * from './src/base/project/ProjectTaskManager';
13+
export * from './src/base/workspace/GitHubIntegration';
14+
export * from './src/base/user/GitHubAuthorization';
1315
export * from './src/dbScheme/businessOperation';
1416
export * from './src/dbScheme/groupedEvent';
1517
export * from './src/dbScheme/notificationsChannels';

build/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ __exportStar(require("./src/base/event/taskManagerItem"), exports);
2626
__exportStar(require("./src/base/event/addons"), exports);
2727
__exportStar(require("./src/base/integrations/integrationToken"), exports);
2828
__exportStar(require("./src/base/project/ProjectTaskManager"), exports);
29+
__exportStar(require("./src/base/workspace/GitHubIntegration"), exports);
30+
__exportStar(require("./src/base/user/GitHubAuthorization"), exports);
2931
__exportStar(require("./src/dbScheme/businessOperation"), exports);
3032
__exportStar(require("./src/dbScheme/groupedEvent"), exports);
3133
__exportStar(require("./src/dbScheme/notificationsChannels"), exports);

build/src/base/project/ProjectTaskManager.d.ts

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ export interface ProjectTaskManagerConfig {
4848
*/
4949
config: {
5050
/**
51-
* GitHub App installation ID
51+
* GitHub App installation ID.
52+
*
53+
* This is a **copy** from workspace.integrations.github.installations[].
54+
* Stored here for worker optimization — allows the worker to operate
55+
* per-project without additional joins/lookups to the workspaces collection.
5256
*/
5357
installationId: string;
5458
/**
@@ -60,57 +64,8 @@ export interface ProjectTaskManagerConfig {
6064
*/
6165
repoFullName: string;
6266
/**
63-
* Delegated user OAuth token for user-to-server authentication
64-
* Used for creating issues and assigning Copilot on behalf of the user
67+
* Primary programming language of the repository (as reported by GitHub)
6568
*/
66-
delegatedUser?: {
67-
/**
68-
* Hawk user ID who authorized the GitHub App
69-
*/
70-
hawkUserId: string;
71-
/**
72-
* GitHub user ID
73-
*/
74-
githubUserId: number;
75-
/**
76-
* GitHub username/login
77-
*/
78-
githubLogin: string;
79-
/**
80-
* OAuth access token (user-to-server token)
81-
*/
82-
accessToken: string;
83-
/**
84-
* Date when access token expires
85-
* null if token expiration is disabled
86-
*/
87-
accessTokenExpiresAt: Date | null;
88-
/**
89-
* OAuth refresh token
90-
* Used to obtain new access tokens when they expire
91-
*/
92-
refreshToken: string;
93-
/**
94-
* Date when refresh token expires
95-
* null if refresh token expiration is disabled
96-
*/
97-
refreshTokenExpiresAt: Date | null;
98-
/**
99-
* Date when token was created/saved
100-
*/
101-
tokenCreatedAt: Date;
102-
/**
103-
* Date when token was last successfully validated
104-
* null if never validated
105-
*/
106-
tokenLastValidatedAt: Date | null;
107-
/**
108-
* Token status
109-
* - active: token is valid (GET /user returns 200)
110-
* - revoked: token was revoked (GET /user returns 401/403) or user removed authorization
111-
* - missing: token is not present in project
112-
*/
113-
status: 'active' | 'revoked' | 'missing';
114-
};
69+
repoLanguage?: string;
11570
};
11671
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* GitHub OAuth authorization stored at user level.
3+
*
4+
* accessToken is NOT stored persistently — it is obtained via refreshToken
5+
* each time an action is needed on behalf of the user (e.g. Copilot assignment).
6+
*
7+
* GitHub may return a new refreshToken during refresh (token rotation),
8+
* so it must be updated in the user document.
9+
*/
10+
export interface GitHubAuthorization {
11+
/**
12+
* GitHub user ID
13+
*/
14+
githubUserId: number;
15+
/**
16+
* GitHub username/login
17+
*/
18+
githubLogin: string;
19+
/**
20+
* OAuth refresh token.
21+
* Used to obtain ephemeral access tokens on demand.
22+
*/
23+
refreshToken: string;
24+
/**
25+
* Date when refresh token expires.
26+
* null if refresh token expiration is disabled by GitHub.
27+
*/
28+
refreshTokenExpiresAt: Date | null;
29+
/**
30+
* Date when this authorization (refreshToken) was originally created/saved
31+
*/
32+
tokenCreatedAt: Date;
33+
/**
34+
* Date when refreshToken was last successfully used to obtain an accessToken.
35+
* null if never validated after initial creation.
36+
*/
37+
tokenLastValidatedAt: Date | null;
38+
/**
39+
* Token status:
40+
* - 'active': token is valid
41+
* - 'revoked': token was revoked or user removed authorization
42+
*/
43+
status: 'active' | 'revoked';
44+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* GitHub App installation account info
3+
*/
4+
export interface GitHubInstallationAccount {
5+
/**
6+
* GitHub account ID
7+
*/
8+
id: number;
9+
/**
10+
* GitHub account login (username or org name)
11+
*/
12+
login: string;
13+
/**
14+
* Account type
15+
*/
16+
type: 'User' | 'Organization';
17+
}
18+
/**
19+
* Delegate user for agent operations (e.g. Copilot assignment).
20+
* Points to a Hawk user who has an active GitHub authorization.
21+
*/
22+
export interface GitHubInstallationDelegatedUser {
23+
/**
24+
* Hawk user ID of the delegate
25+
*/
26+
hawkUserId: string;
27+
/**
28+
* GitHub user ID of the delegate
29+
*/
30+
githubUserId: number;
31+
/**
32+
* GitHub login of the delegate
33+
*/
34+
githubLogin: string;
35+
/**
36+
* Delegate status:
37+
* - 'active': delegate has a valid GitHub authorization
38+
* - 'missing': no workspace member has a GitHub authorization
39+
* - 'revoked': delegate's GitHub authorization was revoked
40+
*/
41+
status: 'active' | 'missing' | 'revoked';
42+
}
43+
/**
44+
* GitHub App installation record stored at workspace level.
45+
*
46+
* GitHub issues installationId per organization/account, not per repository.
47+
* One workspace can have multiple installations
48+
* (e.g. client's GitHub org + personal account).
49+
*/
50+
export interface GitHubInstallation {
51+
/**
52+
* GitHub App installation ID
53+
*/
54+
installationId: number;
55+
/**
56+
* GitHub account where the App is installed
57+
*/
58+
account: GitHubInstallationAccount;
59+
/**
60+
* Hawk user ID of who connected this installation (for audit)
61+
*/
62+
connectedByHawkUserId: string;
63+
/**
64+
* Date when installation was connected
65+
*/
66+
connectedAt: Date;
67+
/**
68+
* Date when installation record was last updated
69+
*/
70+
updatedAt: Date;
71+
/**
72+
* Delegate user for agent actions in Worker
73+
*/
74+
delegatedUser: GitHubInstallationDelegatedUser;
75+
}
76+
/**
77+
* GitHub integration data stored at workspace level
78+
*/
79+
export interface WorkspaceGitHubIntegration {
80+
/**
81+
* List of GitHub App installations for this workspace
82+
*/
83+
installations: GitHubInstallation[];
84+
}
85+
/**
86+
* All integrations stored at workspace level
87+
*/
88+
export interface WorkspaceIntegrations {
89+
/**
90+
* GitHub integration (installations, etc.)
91+
*/
92+
github?: WorkspaceGitHubIntegration;
93+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

build/src/dbScheme/user.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { UserNotificationsDBScheme } from '../../index.ts';
33
import type { BankCard } from './bankCard.ts';
44
import type { MembershipDBScheme } from './membership.ts';
55
import type { UserProjectsLastVisitDBScheme } from './userProjectsLastVisit.ts';
6+
import type { GitHubAuthorization } from '../base/user/GitHubAuthorization.ts';
67
/**
78
* Interface representing how user is stored in DB
89
*/
@@ -78,6 +79,11 @@ export interface UserDBScheme {
7879
*/
7980
term?: string;
8081
};
82+
/**
83+
* GitHub OAuth authorizations.
84+
* Used for user-to-server operations (e.g. Copilot assignment).
85+
*/
86+
githubAuthorizations?: GitHubAuthorization[];
8187
/**
8288
* External identities for SSO (keyed by workspaceId)
8389
*/

build/src/dbScheme/workspace.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { ObjectId } from 'bson';
22
import type { WorkspaceSsoConfig } from './sso.ts';
3+
import type { WorkspaceIntegrations } from '../base/workspace/GitHubIntegration.ts';
34
/**
45
* Workspace representation in DataBase
56
*/
@@ -73,4 +74,8 @@ export interface WorkspaceDBScheme {
7374
* SSO configuration (optional, only for workspaces with SSO enabled)
7475
*/
7576
sso?: WorkspaceSsoConfig;
77+
/**
78+
* External integrations (GitHub, etc.)
79+
*/
80+
integrations?: WorkspaceIntegrations;
7681
}

0 commit comments

Comments
 (0)