fission-worker 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/docker.js +4 -5
- package/dist/docker.js.map +1 -1
- package/package.json +6 -3
- package/runner/common/decorators/current-user.decorator.js +10 -0
- package/runner/common/decorators/public.decorator.js +7 -0
- package/runner/common/decorators/roles.decorator.js +7 -0
- package/runner/common/services/activity-log.service.js +48 -0
- package/runner/common/services/event-bus.service.js +38 -0
- package/runner/modules/github/github.controller.js +155 -0
- package/runner/modules/github/github.module.js +22 -0
- package/runner/modules/github/github.service.js +104 -0
- package/runner/modules/pipeline/data/api-data.service.js +140 -0
- package/runner/modules/pipeline/data/pipeline-data.interface.js +2 -0
- package/runner/modules/pipeline/data/prisma-data.service.js +149 -0
- package/runner/modules/pipeline/pipeline-cto.service.js +129 -0
- package/runner/modules/pipeline/pipeline-helpers.service.js +318 -0
- package/runner/modules/pipeline/pipeline-orchestrator.js +399 -0
- package/runner/modules/pipeline/pipeline-queue.service.js +121 -0
- package/runner/modules/pipeline/pipeline-techlead.service.js +127 -0
- package/runner/modules/pipeline/pipeline-worker.service.js +343 -0
- package/runner/modules/pipeline/pipeline.controller.js +310 -0
- package/runner/modules/pipeline/pipeline.module.js +51 -0
- package/runner/modules/pipeline/pipeline.service.js +706 -0
- package/runner/modules/worker-api/worker-api.controller.js +497 -0
- package/runner/modules/worker-api/worker-api.guard.js +41 -0
- package/runner/modules/worker-api/worker-api.module.js +25 -0
- package/runner/modules/worker-api/worker-dispatch.service.js +87 -0
- package/runner/pipeline-runner/index.js +108 -0
- package/runner/prisma/prisma.service.js +23 -0
package/dist/docker.js
CHANGED
|
@@ -126,12 +126,11 @@ function startSession(job, config, activeSessions) {
|
|
|
126
126
|
* Find the built pipeline-runner script on the host.
|
|
127
127
|
*/
|
|
128
128
|
function findRunnerScript() {
|
|
129
|
-
const home = process.env.HOME || "";
|
|
130
129
|
const candidates = [
|
|
131
|
-
|
|
132
|
-
(0, path_1.join)(
|
|
133
|
-
|
|
134
|
-
(0, path_1.join)(
|
|
130
|
+
// Bundled with the npm package (primary — works for all users)
|
|
131
|
+
(0, path_1.join)(__dirname, "..", "runner", "pipeline-runner", "index.js"),
|
|
132
|
+
// Dev: local Fission repo build
|
|
133
|
+
(0, path_1.join)(__dirname, "..", "..", "..", "..", "dist-runner", "pipeline-runner", "index.js"),
|
|
135
134
|
];
|
|
136
135
|
for (const candidate of candidates) {
|
|
137
136
|
if ((0, fs_1.existsSync)(candidate))
|
package/dist/docker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docker.js","sourceRoot":"","sources":["../src/docker.ts"],"names":[],"mappings":";;AAoBA,oCAqIC;AAzJD,iDAA8D;AAC9D,2BAAmD;AACnD,+BAA4B;AAa5B;;;;GAIG;AACH,SAAgB,YAAY,CAC1B,GAAgB,EAChB,MAAoB,EACpB,cAAyC;IAEzC,MAAM,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,IAAI,GAAG,8CAA8C,CAAC,CAAC;QACrE,gBAAgB,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAC3C,OAAO;IACT,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,WAAI,EAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC;IACpE,MAAM,OAAO,GAAG,IAAA,WAAI,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC;IAE3C,mBAAmB;IACnB,IAAA,cAAS,EAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE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AAC,UAAU,2BAA2B,SAAS,WAAW,EAAE;QACzE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,aAAa,EAAE,UAAU,MAAM,CAAC,MAAM,EAAE;YACxC,cAAc,EAAE,kBAAkB;SACnC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;KACnC,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fission-worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Fission Worker Agent — polls Fission API for pipeline jobs, runs them in Docker containers",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -8,14 +8,17 @@
|
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
|
-
"prepublishOnly": "npm run build",
|
|
11
|
+
"prepublishOnly": "npm run build && npm run bundle-runner",
|
|
12
|
+
"bundle-runner": "rm -rf runner && mkdir -p runner && cp -r ../../dist-runner/* runner/",
|
|
12
13
|
"start": "node dist/index.js start",
|
|
13
14
|
"dev": "tsx src/index.ts start"
|
|
14
15
|
},
|
|
15
16
|
"keywords": ["fission", "pipeline", "worker", "docker", "claude"],
|
|
16
17
|
"license": "MIT",
|
|
17
|
-
"files": ["dist", "README.md"],
|
|
18
|
+
"files": ["dist", "runner", "README.md"],
|
|
18
19
|
"dependencies": {
|
|
20
|
+
"@nestjs/common": "^11.0.0",
|
|
21
|
+
"rxjs": "^7.8.0",
|
|
19
22
|
"commander": "^13.0.0",
|
|
20
23
|
"inquirer": "^12.0.0"
|
|
21
24
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrentUser = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.CurrentUser = (0, common_1.createParamDecorator)((data, ctx) => {
|
|
6
|
+
const request = ctx.switchToHttp().getRequest();
|
|
7
|
+
if (data)
|
|
8
|
+
return request.user?.[data];
|
|
9
|
+
return request.user;
|
|
10
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Public = exports.IS_PUBLIC_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.IS_PUBLIC_KEY = "isPublic";
|
|
6
|
+
const Public = () => (0, common_1.SetMetadata)(exports.IS_PUBLIC_KEY, true);
|
|
7
|
+
exports.Public = Public;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Roles = exports.ROLES_KEY = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
exports.ROLES_KEY = "roles";
|
|
6
|
+
const Roles = (...roles) => (0, common_1.SetMetadata)(exports.ROLES_KEY, roles);
|
|
7
|
+
exports.Roles = Roles;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var ActivityLogService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.ActivityLogService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const prisma_service_1 = require("../../prisma/prisma.service");
|
|
16
|
+
let ActivityLogService = ActivityLogService_1 = class ActivityLogService {
|
|
17
|
+
prisma;
|
|
18
|
+
logger = new common_1.Logger(ActivityLogService_1.name);
|
|
19
|
+
constructor(prisma) {
|
|
20
|
+
this.prisma = prisma;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Write an audit log entry. Never throws — log failures are swallowed
|
|
24
|
+
* so they cannot disrupt the parent operation.
|
|
25
|
+
*/
|
|
26
|
+
async log(action, entityType, entityId, userId, details, ipAddress) {
|
|
27
|
+
try {
|
|
28
|
+
await this.prisma.activityLog.create({
|
|
29
|
+
data: {
|
|
30
|
+
action,
|
|
31
|
+
entityType,
|
|
32
|
+
entityId,
|
|
33
|
+
userId: userId ?? null,
|
|
34
|
+
details: (details ?? undefined),
|
|
35
|
+
ipAddress: ipAddress ?? null,
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
this.logger.error(`Failed to write activity log [${action} ${entityType}/${entityId}]: ${error}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
exports.ActivityLogService = ActivityLogService;
|
|
45
|
+
exports.ActivityLogService = ActivityLogService = ActivityLogService_1 = __decorate([
|
|
46
|
+
(0, common_1.Injectable)(),
|
|
47
|
+
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
|
48
|
+
], ActivityLogService);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var EventBusService_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.EventBusService = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const rxjs_1 = require("rxjs");
|
|
13
|
+
const operators_1 = require("rxjs/operators");
|
|
14
|
+
let EventBusService = EventBusService_1 = class EventBusService {
|
|
15
|
+
logger = new common_1.Logger(EventBusService_1.name);
|
|
16
|
+
subject = new rxjs_1.Subject();
|
|
17
|
+
/**
|
|
18
|
+
* Emit an event for a project. All SSE subscribers for that project
|
|
19
|
+
* will receive it.
|
|
20
|
+
*/
|
|
21
|
+
emit(projectId, type, data) {
|
|
22
|
+
this.logger.debug(`Event [${type}] for project ${projectId}`);
|
|
23
|
+
this.subject.next({ projectId, type, data });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get an observable stream of MessageEvents filtered to a specific project.
|
|
27
|
+
* Each emitted value conforms to NestJS's MessageEvent interface for SSE.
|
|
28
|
+
*/
|
|
29
|
+
getStream(projectId) {
|
|
30
|
+
return this.subject.pipe((0, operators_1.filter)((e) => e.projectId === projectId), (0, operators_1.map)((e) => ({
|
|
31
|
+
data: JSON.stringify({ type: e.type, data: e.data }),
|
|
32
|
+
})));
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.EventBusService = EventBusService;
|
|
36
|
+
exports.EventBusService = EventBusService = EventBusService_1 = __decorate([
|
|
37
|
+
(0, common_1.Injectable)()
|
|
38
|
+
], EventBusService);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var GithubController_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.GithubController = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const throttler_1 = require("@nestjs/throttler");
|
|
19
|
+
const prisma_service_1 = require("../../prisma/prisma.service");
|
|
20
|
+
const public_decorator_1 = require("../../common/decorators/public.decorator");
|
|
21
|
+
const github_service_1 = require("./github.service");
|
|
22
|
+
let GithubController = GithubController_1 = class GithubController {
|
|
23
|
+
github;
|
|
24
|
+
prisma;
|
|
25
|
+
logger = new common_1.Logger(GithubController_1.name);
|
|
26
|
+
constructor(github, prisma) {
|
|
27
|
+
this.github = github;
|
|
28
|
+
this.prisma = prisma;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* GET /github/install?projectId=xxx
|
|
32
|
+
* Redirects the user to GitHub to install the Fission Pipeline app.
|
|
33
|
+
* The projectId is passed as state so we can link the installation on callback.
|
|
34
|
+
*/
|
|
35
|
+
async install(projectId, res) {
|
|
36
|
+
const url = this.github.getInstallUrl(projectId);
|
|
37
|
+
res.status(302).header("Location", url).send();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* GET /github/callback?installation_id=xxx&setup_action=install&state=projectId
|
|
41
|
+
* GitHub redirects here after the user installs the app.
|
|
42
|
+
* We store the installation ID on the project's repositories.
|
|
43
|
+
*/
|
|
44
|
+
async callback(installationId, setupAction, state, res) {
|
|
45
|
+
this.logger.log(`GitHub callback: installation_id=${installationId} action=${setupAction} state=${state}`);
|
|
46
|
+
if (setupAction === "install" && installationId && state) {
|
|
47
|
+
const installId = parseInt(installationId, 10);
|
|
48
|
+
const projectId = state;
|
|
49
|
+
// Get the list of repos this installation has access to
|
|
50
|
+
try {
|
|
51
|
+
const repos = await this.github.getInstallationRepos(installId);
|
|
52
|
+
// Update all matching repositories for this project
|
|
53
|
+
const projectRepos = await this.prisma.repository.findMany({
|
|
54
|
+
where: { projectId },
|
|
55
|
+
});
|
|
56
|
+
for (const projRepo of projectRepos) {
|
|
57
|
+
// Match by comparing the repoUrl with the GitHub repo full_name
|
|
58
|
+
const match = repos.find((r) => {
|
|
59
|
+
const fullName = r.full_name.toLowerCase();
|
|
60
|
+
return (projRepo.repoUrl.toLowerCase().includes(fullName) ||
|
|
61
|
+
fullName.includes(projRepo.name.toLowerCase()));
|
|
62
|
+
});
|
|
63
|
+
if (match) {
|
|
64
|
+
const [owner, repo] = match.full_name.split("/");
|
|
65
|
+
await this.prisma.repository.update({
|
|
66
|
+
where: { id: projRepo.id },
|
|
67
|
+
data: {
|
|
68
|
+
githubInstallationId: installId,
|
|
69
|
+
githubOwner: owner,
|
|
70
|
+
githubRepo: repo,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
this.logger.log(`Linked repo ${projRepo.name} → ${match.full_name} (installation: ${installId})`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
// If no existing repos matched, store installation on all project repos
|
|
77
|
+
if (projectRepos.length > 0) {
|
|
78
|
+
await this.prisma.repository.updateMany({
|
|
79
|
+
where: { projectId, githubInstallationId: null },
|
|
80
|
+
data: { githubInstallationId: installId },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
this.logger.error(`Failed to process GitHub installation: ${err}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Redirect back to the project page in the dashboard
|
|
89
|
+
const redirectUrl = state
|
|
90
|
+
? `/projects/${state}`
|
|
91
|
+
: "/projects";
|
|
92
|
+
res.status(302).header("Location", redirectUrl).send();
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* GET /github/repos/:installationId
|
|
96
|
+
* List repositories accessible to a GitHub App installation.
|
|
97
|
+
*/
|
|
98
|
+
async listRepos(installationId) {
|
|
99
|
+
const repos = await this.github.getInstallationRepos(parseInt(installationId, 10));
|
|
100
|
+
return {
|
|
101
|
+
data: repos.map((r) => ({
|
|
102
|
+
fullName: r.full_name,
|
|
103
|
+
private: r.private,
|
|
104
|
+
cloneUrl: r.clone_url,
|
|
105
|
+
defaultBranch: r.default_branch,
|
|
106
|
+
})),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* GET /github/status
|
|
111
|
+
* Check if GitHub App is configured.
|
|
112
|
+
*/
|
|
113
|
+
async status() {
|
|
114
|
+
return { data: { configured: this.github.isConfigured() } };
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
exports.GithubController = GithubController;
|
|
118
|
+
__decorate([
|
|
119
|
+
(0, common_1.Get)("install"),
|
|
120
|
+
__param(0, (0, common_1.Query)("projectId")),
|
|
121
|
+
__param(1, (0, common_1.Res)()),
|
|
122
|
+
__metadata("design:type", Function),
|
|
123
|
+
__metadata("design:paramtypes", [String, Object]),
|
|
124
|
+
__metadata("design:returntype", Promise)
|
|
125
|
+
], GithubController.prototype, "install", null);
|
|
126
|
+
__decorate([
|
|
127
|
+
(0, common_1.Get)("callback"),
|
|
128
|
+
__param(0, (0, common_1.Query)("installation_id")),
|
|
129
|
+
__param(1, (0, common_1.Query)("setup_action")),
|
|
130
|
+
__param(2, (0, common_1.Query)("state")),
|
|
131
|
+
__param(3, (0, common_1.Res)()),
|
|
132
|
+
__metadata("design:type", Function),
|
|
133
|
+
__metadata("design:paramtypes", [String, String, String, Object]),
|
|
134
|
+
__metadata("design:returntype", Promise)
|
|
135
|
+
], GithubController.prototype, "callback", null);
|
|
136
|
+
__decorate([
|
|
137
|
+
(0, common_1.Get)("repos/:installationId"),
|
|
138
|
+
__param(0, (0, common_1.Param)("installationId")),
|
|
139
|
+
__metadata("design:type", Function),
|
|
140
|
+
__metadata("design:paramtypes", [String]),
|
|
141
|
+
__metadata("design:returntype", Promise)
|
|
142
|
+
], GithubController.prototype, "listRepos", null);
|
|
143
|
+
__decorate([
|
|
144
|
+
(0, common_1.Get)("status"),
|
|
145
|
+
__metadata("design:type", Function),
|
|
146
|
+
__metadata("design:paramtypes", []),
|
|
147
|
+
__metadata("design:returntype", Promise)
|
|
148
|
+
], GithubController.prototype, "status", null);
|
|
149
|
+
exports.GithubController = GithubController = GithubController_1 = __decorate([
|
|
150
|
+
(0, common_1.Controller)("github"),
|
|
151
|
+
(0, public_decorator_1.Public)(),
|
|
152
|
+
(0, throttler_1.SkipThrottle)({ global: true }),
|
|
153
|
+
__metadata("design:paramtypes", [github_service_1.GithubService,
|
|
154
|
+
prisma_service_1.PrismaService])
|
|
155
|
+
], GithubController);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GithubModule = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
const github_service_1 = require("./github.service");
|
|
12
|
+
const github_controller_1 = require("./github.controller");
|
|
13
|
+
let GithubModule = class GithubModule {
|
|
14
|
+
};
|
|
15
|
+
exports.GithubModule = GithubModule;
|
|
16
|
+
exports.GithubModule = GithubModule = __decorate([
|
|
17
|
+
(0, common_1.Module)({
|
|
18
|
+
controllers: [github_controller_1.GithubController],
|
|
19
|
+
providers: [github_service_1.GithubService],
|
|
20
|
+
exports: [github_service_1.GithubService],
|
|
21
|
+
})
|
|
22
|
+
], GithubModule);
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var GithubService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.GithubService = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const config_1 = require("@nestjs/config");
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const jsonwebtoken_1 = require("jsonwebtoken");
|
|
18
|
+
let GithubService = GithubService_1 = class GithubService {
|
|
19
|
+
config;
|
|
20
|
+
logger = new common_1.Logger(GithubService_1.name);
|
|
21
|
+
appId;
|
|
22
|
+
privateKey;
|
|
23
|
+
constructor(config) {
|
|
24
|
+
this.config = config;
|
|
25
|
+
this.appId = this.config.get("GITHUB_APP_ID", "");
|
|
26
|
+
const keyPath = this.config.get("GITHUB_PRIVATE_KEY_PATH", "");
|
|
27
|
+
try {
|
|
28
|
+
this.privateKey = keyPath ? (0, fs_1.readFileSync)(keyPath, "utf-8") : "";
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
this.logger.warn("GitHub App private key not found — GitHub integration disabled");
|
|
32
|
+
this.privateKey = "";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Whether the GitHub App is configured. */
|
|
36
|
+
isConfigured() {
|
|
37
|
+
return !!(this.appId && this.privateKey);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate a JWT for authenticating as the GitHub App.
|
|
41
|
+
* Valid for 10 minutes (GitHub max).
|
|
42
|
+
*/
|
|
43
|
+
generateAppJwt() {
|
|
44
|
+
const now = Math.floor(Date.now() / 1000);
|
|
45
|
+
return (0, jsonwebtoken_1.sign)({
|
|
46
|
+
iat: now - 60, // 60 seconds in the past for clock drift
|
|
47
|
+
exp: now + 10 * 60, // 10 minutes
|
|
48
|
+
iss: this.appId,
|
|
49
|
+
}, this.privateKey, { algorithm: "RS256" });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generate a short-lived installation access token for a specific installation.
|
|
53
|
+
* This token can clone/push to repos the installation has access to.
|
|
54
|
+
*/
|
|
55
|
+
async getInstallationToken(installationId) {
|
|
56
|
+
const jwt = this.generateAppJwt();
|
|
57
|
+
const res = await fetch(`https://api.github.com/app/installations/${installationId}/access_tokens`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
Authorization: `Bearer ${jwt}`,
|
|
61
|
+
Accept: "application/vnd.github+json",
|
|
62
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
if (!res.ok) {
|
|
66
|
+
const body = await res.text();
|
|
67
|
+
throw new Error(`GitHub installation token failed: ${res.status} ${body}`);
|
|
68
|
+
}
|
|
69
|
+
const data = (await res.json());
|
|
70
|
+
return data.token;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* List repositories accessible to an installation.
|
|
74
|
+
*/
|
|
75
|
+
async getInstallationRepos(installationId) {
|
|
76
|
+
const token = await this.getInstallationToken(installationId);
|
|
77
|
+
const res = await fetch("https://api.github.com/installation/repositories?per_page=100", {
|
|
78
|
+
headers: {
|
|
79
|
+
Authorization: `Bearer ${token}`,
|
|
80
|
+
Accept: "application/vnd.github+json",
|
|
81
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
const body = await res.text();
|
|
86
|
+
throw new Error(`GitHub list repos failed: ${res.status} ${body}`);
|
|
87
|
+
}
|
|
88
|
+
const data = (await res.json());
|
|
89
|
+
return data.repositories;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the installation URL for the GitHub App.
|
|
93
|
+
* Redirect users here to install the app on their repos.
|
|
94
|
+
*/
|
|
95
|
+
getInstallUrl(state) {
|
|
96
|
+
const base = `https://github.com/apps/fission-pipeline/installations/new`;
|
|
97
|
+
return state ? `${base}?state=${encodeURIComponent(state)}` : base;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
exports.GithubService = GithubService;
|
|
101
|
+
exports.GithubService = GithubService = GithubService_1 = __decorate([
|
|
102
|
+
(0, common_1.Injectable)(),
|
|
103
|
+
__metadata("design:paramtypes", [config_1.ConfigService])
|
|
104
|
+
], GithubService);
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ApiDataService = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* HTTP-based data source for the pipeline engine running inside
|
|
6
|
+
* a worker container. Calls the Fission Worker API.
|
|
7
|
+
*
|
|
8
|
+
* NOT a NestJS Injectable — instantiated manually in pipeline-runner.ts.
|
|
9
|
+
*/
|
|
10
|
+
class ApiDataService {
|
|
11
|
+
baseUrl;
|
|
12
|
+
apiKey;
|
|
13
|
+
sessionId;
|
|
14
|
+
constructor(baseUrl, apiKey, sessionId) {
|
|
15
|
+
this.baseUrl = baseUrl;
|
|
16
|
+
this.apiKey = apiKey;
|
|
17
|
+
this.sessionId = sessionId;
|
|
18
|
+
}
|
|
19
|
+
async request(method, path, body) {
|
|
20
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
21
|
+
method,
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
},
|
|
26
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
27
|
+
});
|
|
28
|
+
if (!res.ok) {
|
|
29
|
+
throw new Error(`Worker API ${method} ${path} failed: ${res.status} ${res.statusText}`);
|
|
30
|
+
}
|
|
31
|
+
const text = await res.text();
|
|
32
|
+
return text ? JSON.parse(text) : undefined;
|
|
33
|
+
}
|
|
34
|
+
// -- Tasks ------------------------------------------------------------ //
|
|
35
|
+
async findTasks(projectId, filter) {
|
|
36
|
+
const params = new URLSearchParams();
|
|
37
|
+
if (filter.status) {
|
|
38
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
39
|
+
params.set("status", statuses.join(","));
|
|
40
|
+
}
|
|
41
|
+
if (filter.retryCountLt !== undefined)
|
|
42
|
+
params.set("retryCountLt", String(filter.retryCountLt));
|
|
43
|
+
if (filter.take)
|
|
44
|
+
params.set("take", String(filter.take));
|
|
45
|
+
return this.request("GET", `/api/v1/worker/projects/${projectId}/tasks?${params}`);
|
|
46
|
+
}
|
|
47
|
+
async findFirstTask(projectId, filter) {
|
|
48
|
+
const tasks = await this.findTasks(projectId, { ...filter, take: 1 });
|
|
49
|
+
return tasks.length > 0 ? tasks[0] : null;
|
|
50
|
+
}
|
|
51
|
+
async updateTask(id, data) {
|
|
52
|
+
return this.request("PATCH", `/api/v1/worker/tasks/${id}`, data);
|
|
53
|
+
}
|
|
54
|
+
async createTask(data) {
|
|
55
|
+
return this.request("POST", `/api/v1/worker/tasks`, data);
|
|
56
|
+
}
|
|
57
|
+
// -- Task Comments ---------------------------------------------------- //
|
|
58
|
+
async findTaskComments(taskId, options) {
|
|
59
|
+
const params = new URLSearchParams();
|
|
60
|
+
if (options?.take)
|
|
61
|
+
params.set("take", String(options.take));
|
|
62
|
+
return this.request("GET", `/api/v1/worker/tasks/${taskId}/comments?${params}`);
|
|
63
|
+
}
|
|
64
|
+
async createTaskComment(data) {
|
|
65
|
+
await this.request("POST", `/api/v1/worker/tasks/${data.taskId}/comments`, {
|
|
66
|
+
author: data.author,
|
|
67
|
+
content: data.content,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
// -- Findings --------------------------------------------------------- //
|
|
71
|
+
async findFindings(projectId, filter) {
|
|
72
|
+
const params = new URLSearchParams();
|
|
73
|
+
if (filter.status) {
|
|
74
|
+
const statuses = Array.isArray(filter.status) ? filter.status : [filter.status];
|
|
75
|
+
params.set("status", statuses.join(","));
|
|
76
|
+
}
|
|
77
|
+
if (filter.source)
|
|
78
|
+
params.set("source", filter.source);
|
|
79
|
+
if (filter.take)
|
|
80
|
+
params.set("take", String(filter.take));
|
|
81
|
+
return this.request("GET", `/api/v1/worker/projects/${projectId}/findings?${params}`);
|
|
82
|
+
}
|
|
83
|
+
async findFirstFinding(projectId, filter) {
|
|
84
|
+
const findings = await this.findFindings(projectId, { ...filter, take: 1 });
|
|
85
|
+
return findings.length > 0 ? findings[0] : null;
|
|
86
|
+
}
|
|
87
|
+
async findFindingById(id) {
|
|
88
|
+
try {
|
|
89
|
+
return await this.request("GET", `/api/v1/worker/findings/${id}`);
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async createFinding(data) {
|
|
96
|
+
return this.request("POST", `/api/v1/worker/findings`, data);
|
|
97
|
+
}
|
|
98
|
+
async updateFinding(id, data) {
|
|
99
|
+
await this.request("PATCH", `/api/v1/worker/findings/${id}`, data);
|
|
100
|
+
}
|
|
101
|
+
async updateManyFindings(ids, data) {
|
|
102
|
+
await this.request("PATCH", `/api/v1/worker/findings/bulk`, { ids, ...data });
|
|
103
|
+
}
|
|
104
|
+
// -- Sessions --------------------------------------------------------- //
|
|
105
|
+
async updateSession(id, data) {
|
|
106
|
+
await this.request("PATCH", `/api/v1/worker/sessions/${id}`, {
|
|
107
|
+
...data,
|
|
108
|
+
endedAt: data.endedAt?.toISOString(),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
async findSession(id) {
|
|
112
|
+
try {
|
|
113
|
+
return await this.request("GET", `/api/v1/worker/sessions/${id}`);
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// -- Events ----------------------------------------------------------- //
|
|
120
|
+
emit(projectId, type, data) {
|
|
121
|
+
this.request("POST", "/api/v1/worker/events", {
|
|
122
|
+
projectId,
|
|
123
|
+
type,
|
|
124
|
+
data,
|
|
125
|
+
sessionId: this.sessionId,
|
|
126
|
+
}).catch(() => { });
|
|
127
|
+
}
|
|
128
|
+
// -- Activity Log ----------------------------------------------------- //
|
|
129
|
+
async log(action, entityType, entityId, userId, details) {
|
|
130
|
+
await this.request("POST", "/api/v1/worker/activity-log", {
|
|
131
|
+
action,
|
|
132
|
+
entityType,
|
|
133
|
+
entityId,
|
|
134
|
+
userId,
|
|
135
|
+
details,
|
|
136
|
+
sessionId: this.sessionId,
|
|
137
|
+
}).catch(() => { });
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.ApiDataService = ApiDataService;
|