@eclipse-che/che-devworkspace-generator 0.0.1-602dcb4 → 0.0.1-6ef61ae

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.
Files changed (66) hide show
  1. package/lib/bitbucket/bitbucket-module.d.ts +12 -0
  2. package/lib/bitbucket/bitbucket-module.js +21 -0
  3. package/lib/bitbucket/bitbucket-module.js.map +1 -0
  4. package/lib/bitbucket/bitbucket-resolver.d.ts +17 -0
  5. package/lib/bitbucket/bitbucket-resolver.js +56 -0
  6. package/lib/bitbucket/bitbucket-resolver.js.map +1 -0
  7. package/lib/bitbucket/bitbucket-url.d.ts +22 -0
  8. package/lib/bitbucket/bitbucket-url.js +38 -0
  9. package/lib/bitbucket/bitbucket-url.js.map +1 -0
  10. package/lib/bitbucket-server/bitbucket-server-module.d.ts +12 -0
  11. package/lib/bitbucket-server/bitbucket-server-module.js +21 -0
  12. package/lib/bitbucket-server/bitbucket-server-module.js.map +1 -0
  13. package/lib/bitbucket-server/bitbucket-server-resolver.d.ts +17 -0
  14. package/lib/bitbucket-server/bitbucket-server-resolver.js +64 -0
  15. package/lib/bitbucket-server/bitbucket-server-resolver.js.map +1 -0
  16. package/lib/bitbucket-server/bitbucket-server-url.d.ts +24 -0
  17. package/lib/bitbucket-server/bitbucket-server-url.js +43 -0
  18. package/lib/bitbucket-server/bitbucket-server-url.js.map +1 -0
  19. package/lib/generate.d.ts +0 -1
  20. package/lib/generate.js +5 -18
  21. package/lib/generate.js.map +1 -1
  22. package/lib/github/github-module.js +3 -1
  23. package/lib/github/github-module.js.map +1 -1
  24. package/lib/github/github-resolver.d.ts +6 -7
  25. package/lib/github/github-resolver.js +6 -3
  26. package/lib/github/github-resolver.js.map +1 -1
  27. package/lib/github/github-url.d.ts +2 -4
  28. package/lib/github/github-url.js +0 -3
  29. package/lib/github/github-url.js.map +1 -1
  30. package/lib/inversify/inversify-binding.js +6 -0
  31. package/lib/inversify/inversify-binding.js.map +1 -1
  32. package/lib/main.js +8 -8
  33. package/lib/main.js.map +1 -1
  34. package/lib/resolve/git-url-resolver.d.ts +5 -0
  35. package/lib/resolve/git-url-resolver.js +43 -0
  36. package/lib/resolve/git-url-resolver.js.map +1 -0
  37. package/lib/resolve/resolve-module.d.ts +12 -0
  38. package/lib/resolve/resolve-module.js +19 -0
  39. package/lib/resolve/resolve-module.js.map +1 -0
  40. package/lib/resolve/resolver.d.ts +22 -0
  41. package/lib/resolve/resolver.js +12 -0
  42. package/lib/resolve/resolver.js.map +1 -0
  43. package/lib/resolve/url.d.ts +35 -0
  44. package/lib/resolve/url.js +12 -0
  45. package/lib/resolve/url.js.map +1 -0
  46. package/lib/types.d.ts +13 -0
  47. package/lib/types.js +17 -0
  48. package/lib/types.js.map +1 -0
  49. package/package.json +1 -1
  50. package/src/bitbucket/bitbucket-module.ts +21 -0
  51. package/src/bitbucket/bitbucket-resolver.ts +46 -0
  52. package/src/bitbucket/bitbucket-url.ts +41 -0
  53. package/src/bitbucket-server/bitbucket-server-module.ts +21 -0
  54. package/src/bitbucket-server/bitbucket-server-resolver.ts +53 -0
  55. package/src/bitbucket-server/bitbucket-server-url.ts +51 -0
  56. package/src/generate.ts +2 -20
  57. package/src/github/github-module.ts +4 -1
  58. package/src/github/github-resolver.ts +13 -7
  59. package/src/github/github-url.ts +3 -4
  60. package/src/inversify/inversify-binding.ts +6 -0
  61. package/src/main.ts +8 -8
  62. package/src/resolve/git-url-resolver.ts +30 -0
  63. package/src/resolve/resolve-module.ts +18 -0
  64. package/src/resolve/resolver.ts +25 -0
  65. package/src/resolve/url.ts +40 -0
  66. package/src/types.ts +14 -0
@@ -8,10 +8,9 @@
8
8
  * SPDX-License-Identifier: EPL-2.0
9
9
  ***********************************************************************/
10
10
 
11
- /**
12
- * Provides helper methods on top of github URL to get for example raw content of get relative links
13
- */
14
- export class GithubUrl {
11
+ import { Url } from '../resolve/url';
12
+
13
+ export class GithubUrl implements Url {
15
14
  constructor(
16
15
  private readonly scheme: string,
17
16
  private readonly hostName: string,
@@ -14,7 +14,10 @@ import { Container } from 'inversify';
14
14
  import { devfileModule } from '../devfile/devfile-module';
15
15
  import { fetchModule } from '../fetch/fetch-module';
16
16
  import { githubModule } from '../github/github-module';
17
+ import { resolveModule } from '../resolve/resolve-module';
17
18
  import { pluginRegistryModule } from '../plugin-registry/plugin-registry-module';
19
+ import { bitbucketModule } from '../bitbucket/bitbucket-module';
20
+ import { bitbucketServerModule } from '../bitbucket-server/bitbucket-server-module';
18
21
 
19
22
  /**
20
23
  * Manage all bindings for inversify
@@ -28,6 +31,9 @@ export class InversifyBinding {
28
31
  this.container.load(devfileModule);
29
32
  this.container.load(fetchModule);
30
33
  this.container.load(githubModule);
34
+ this.container.load(bitbucketModule);
35
+ this.container.load(bitbucketServerModule);
36
+ this.container.load(resolveModule);
31
37
  this.container.load(pluginRegistryModule);
32
38
 
33
39
  this.container.bind(Symbol.for('AxiosInstance')).toConstantValue(options.axiosInstance);
package/src/main.ts CHANGED
@@ -11,13 +11,13 @@
11
11
  import * as axios from 'axios';
12
12
  import * as fs from 'fs-extra';
13
13
  import { Generate } from './generate';
14
- import { GithubResolver } from './github/github-resolver';
15
14
  import * as jsYaml from 'js-yaml';
16
15
  import { InversifyBinding } from './inversify/inversify-binding';
17
16
  import { UrlFetcher } from './fetch/url-fetcher';
18
17
  import { PluginRegistryResolver } from './plugin-registry/plugin-registry-resolver';
19
18
  import { V1alpha2DevWorkspaceSpecTemplate } from '@devfile/api';
20
19
  import { DevfileContext } from './api/devfile-context';
20
+ import { GitUrlResolver } from './resolve/git-url-resolver';
21
21
 
22
22
  export class Main {
23
23
  /**
@@ -69,12 +69,12 @@ export class Main {
69
69
  let devfileContent;
70
70
  let editorContent;
71
71
 
72
- // gets the github URL
72
+ // gets the repo URL
73
73
  if (params.devfileUrl) {
74
- const githubResolver = container.get(GithubResolver);
75
- const githubUrl = githubResolver.resolve(params.devfileUrl);
74
+ const resolver = container.get(GitUrlResolver);
75
+ const url = resolver.resolve(params.devfileUrl);
76
76
  // user devfile
77
- devfileContent = await container.get(UrlFetcher).fetchText(githubUrl.getContentUrl('devfile.yaml'));
77
+ devfileContent = await container.get(UrlFetcher).fetchText(url.getContentUrl('devfile.yaml'));
78
78
 
79
79
  // load content
80
80
  const devfileParsed = jsYaml.load(devfileContent);
@@ -84,10 +84,10 @@ export class Main {
84
84
  // no, so add the current project being cloned
85
85
  devfileParsed.projects = [
86
86
  {
87
- name: githubUrl.getRepoName(),
87
+ name: url.getRepoName(),
88
88
  git: {
89
- remotes: { origin: githubUrl.getCloneUrl() },
90
- checkoutFrom: { revision: githubUrl.getBranchName() },
89
+ remotes: { origin: url.getCloneUrl() },
90
+ checkoutFrom: { revision: url.getBranchName() },
91
91
  },
92
92
  },
93
93
  ];
@@ -0,0 +1,30 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ import { injectable, multiInject } from 'inversify';
11
+ import { Url } from './url';
12
+ import { TYPES } from '../types';
13
+ import { Resolver } from './resolver';
14
+
15
+ const { Resolver } = TYPES;
16
+
17
+ @injectable()
18
+ export class GitUrlResolver {
19
+ @multiInject(Resolver)
20
+ private resolvers: Resolver[];
21
+
22
+ resolve(link: string): Url {
23
+ const resolver = this.resolvers.find(r => r.isValid(link));
24
+ if (resolver) {
25
+ return resolver.resolve(link);
26
+ } else {
27
+ throw new Error('Can not resolver the URL');
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,18 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ import { ContainerModule, interfaces } from 'inversify';
11
+
12
+ import { GitUrlResolver } from './git-url-resolver';
13
+
14
+ const resolveModule = new ContainerModule((bind: interfaces.Bind) => {
15
+ bind(GitUrlResolver).toSelf().inSingletonScope();
16
+ });
17
+
18
+ export { resolveModule };
@@ -0,0 +1,25 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+
11
+ import { Url } from './url';
12
+
13
+ export interface Resolver {
14
+ /**
15
+ * Validates the string url for belonging to a specific Git provider.
16
+ * @param url string representation of Url.
17
+ */
18
+ isValid(url: string): boolean;
19
+
20
+ /**
21
+ * Resolves repository string URL to a {@class Url} object.
22
+ * @param url string representation of Url.
23
+ */
24
+ resolve(url: string): Url;
25
+ }
@@ -0,0 +1,40 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+
11
+ /**
12
+ * Url object
13
+ */
14
+ export interface Url {
15
+ /**
16
+ * Provides RAW file content url
17
+ * @param path file path
18
+ */
19
+ getContentUrl(path: string);
20
+
21
+ /**
22
+ * Provides repositories Url
23
+ */
24
+ getUrl(): string;
25
+
26
+ /**
27
+ * Provides Git clone url
28
+ */
29
+ getCloneUrl(): string;
30
+
31
+ /**
32
+ * Provides repository name
33
+ */
34
+ getRepoName(): string;
35
+
36
+ /**
37
+ * Provides branch name if initialised.
38
+ */
39
+ getBranchName(): string;
40
+ }
package/src/types.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**********************************************************************
2
+ * Copyright (c) 2023 Red Hat, Inc.
3
+ *
4
+ * This program and the accompanying materials are made
5
+ * available under the terms of the Eclipse Public License 2.0
6
+ * which is available at https://www.eclipse.org/legal/epl-2.0/
7
+ *
8
+ * SPDX-License-Identifier: EPL-2.0
9
+ ***********************************************************************/
10
+ const TYPES = {
11
+ Resolver: Symbol.for('Resolver'),
12
+ };
13
+
14
+ export { TYPES };