1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.streamFiles = exports.streamFilesFrom = exports.copyFiles = exports.copyFilesFrom = exports.copyFileFromUrl = void 0;
|
19 | const configuration_1 = require("@atomist/automation-client/lib/configuration");
|
20 | const GitCommandGitProject_1 = require("@atomist/automation-client/lib/project/git/GitCommandGitProject");
|
21 | const httpClient_1 = require("@atomist/automation-client/lib/spi/http/httpClient");
|
22 | const logger_1 = require("@atomist/automation-client/lib/util/logger");
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function copyFileFromUrl(url, path) {
|
29 | return async (p) => {
|
30 | const http = configuration_1.configurationValue("http.client.factory", httpClient_1.defaultHttpClientFactory());
|
31 | const response = await http.create(url).exchange(url, { method: httpClient_1.HttpMethod.Get });
|
32 | return p.addFile(path, response.body);
|
33 | };
|
34 | }
|
35 | exports.copyFileFromUrl = copyFileFromUrl;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function copyFilesFrom(donorProjectId, fileMappings, credentials) {
|
44 | return async (p, i) => {
|
45 | const donorProject = await GitCommandGitProject_1.GitCommandGitProject.cloned(credentials, donorProjectId);
|
46 | return copyFiles(donorProject, fileMappings)(p, i);
|
47 | };
|
48 | }
|
49 | exports.copyFilesFrom = copyFilesFrom;
|
50 | function copyFiles(donorProject, fileMappings) {
|
51 | return async (p) => {
|
52 | for (const m of fileMappings) {
|
53 | const fm = typeof m === "string" ? { donorPath: m, recipientPath: m } : m;
|
54 | const found = await donorProject.getFile(fm.donorPath);
|
55 | if (found) {
|
56 | await p.addFile(fm.recipientPath, await found.getContent());
|
57 | }
|
58 | else {
|
59 | logger_1.logger.debug("Path '%s' not found in donor project %s:%s", fm.donorPath, donorProject.id.owner, donorProject.id.repo);
|
60 | }
|
61 | }
|
62 | return p;
|
63 | };
|
64 | }
|
65 | exports.copyFiles = copyFiles;
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | function streamFilesFrom(donorProjectId, fileGlobMapping) {
|
73 | return async (p, i) => {
|
74 | const donorProject = await GitCommandGitProject_1.GitCommandGitProject.cloned(i.credentials, donorProjectId);
|
75 | return streamFiles(donorProject, fileGlobMapping)(p, i);
|
76 | };
|
77 | }
|
78 | exports.streamFilesFrom = streamFilesFrom;
|
79 | function streamFiles(donorProject, fileGlobMapping) {
|
80 | return async (p) => {
|
81 | const fileStream = donorProject.streamFiles(...fileGlobMapping.globPatterns);
|
82 | await new Promise((resolve, reject) => {
|
83 | fileStream
|
84 | .on("end", () => {
|
85 | logger_1.logger.debug("end of file stream reached, using glob: ", fileGlobMapping);
|
86 | resolve();
|
87 | })
|
88 | .on("data", donorFile => {
|
89 | const newPath = (fileGlobMapping.recipientPath || "") + donorFile.path;
|
90 | p.addFileSync(newPath, donorFile.getContentSync());
|
91 | logger_1.logger.log("silly", "file added: ", donorFile.path);
|
92 | })
|
93 | .on("error", e => {
|
94 | logger_1.logger.debug("Error copying file: ", e);
|
95 | reject(e);
|
96 | });
|
97 | });
|
98 | };
|
99 | }
|
100 | exports.streamFiles = streamFiles;
|
101 |
|
\ | No newline at end of file |