From 497cfba2e491c041cf8f924e64edfd153e40de82 Mon Sep 17 00:00:00 2001 From: Urook <95576653+Urook@users.noreply.github.com> Date: Tue, 7 Mar 2023 11:44:15 +0200 Subject: [PATCH] Bitbucket On Prem - Support Fetching Instance Version (#353) --- graphql/schema.graphql | 12 ++++++++++++ package.json | 2 +- src/BitBucketOnPrem.ts | 31 +++++++++++++++++++++++++++++++ src/api.ts | 7 ++++++- 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 2c8398d..c2dbcdd 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -59,6 +59,10 @@ input BitbucketTreeInput { maxResults: Int } +input BitbucketPropertiesInput { + url: String! +} + enum SupportedServerLanguage { java python @@ -124,6 +128,7 @@ type BitbucketOnPrem { commit(args: BitbucketInput!): BitbucketCommit branches(args: BitbucketInput!): [BitbucketBranch] file(args: BitbucketInput!): String + bitbucketProperties(args: BitbucketPropertiesInput!): BitbucketProperties } type BitbucketUser { @@ -177,6 +182,13 @@ type BitbucketBranch { isDefault: Boolean! } +type BitbucketProperties { + version: String + buildNumber: String + buildDate: String + displayName: String +} + type Log { level: String! time: String! diff --git a/package.json b/package.json index e75f155..9d49841 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "explorook", - "version": "1.14.3", + "version": "1.14.4", "description": "Rookout's site addon to support local files and folders", "main": "dist/index.js", "scripts": { diff --git a/src/BitBucketOnPrem.ts b/src/BitBucketOnPrem.ts index 6f88237..b564001 100644 --- a/src/BitBucketOnPrem.ts +++ b/src/BitBucketOnPrem.ts @@ -54,6 +54,10 @@ export interface BitbucketOnPremRepoProps { maxResults?: number; } +export interface BitbucketOnPremPropertiesInputProps { + url: string; +} + export interface BitBucketOnPremInput { args: BitbucketOnPrem; } @@ -62,6 +66,17 @@ export interface BitbucketOnPremTreeInput { args: BitbucketOnPremRepoProps; } +export interface BitbucketPropertiesInput { + args: BitbucketOnPremPropertiesInputProps; +} + +export interface BitbucketProperties { + version: string; + buildNumber: string; + buildDate: string; + displayName: string; +} + const getRepoId = ({projectKey, repoName, commit}: {projectKey: string, repoName: string, commit: string}) => { return `${projectKey}::${repoName}::${commit}`; }; @@ -506,6 +521,22 @@ export const getCommitDetailsFromBitbucket = async ({url, accessToken, projectKe return res.json(); }; +export const getBitbucketProperties = + async ({url}: BitbucketOnPremPropertiesInputProps): Promise => { + + const bitbucketPropertiesUrl = UrlAssembler(url).template("/rest/api/1.0/application-properties").toString(); + + logger.debug("Getting Bitbucket server's properties using", { bitbucketPropertiesUrl }); + try { + const res = await fetchNoCache(bitbucketPropertiesUrl, {}); // Empty second param is required, using default values + if (res.ok) { + return res.json(); + } + } catch (error) { + logger.error("Failed to fetch bitbucket properties", { error }); + } + }; + const addSlugToUrl = (url: string, slug: string): string => { if (!slug) { return url; diff --git a/src/api.ts b/src/api.ts index 27f0161..4f53de0 100644 --- a/src/api.ts +++ b/src/api.ts @@ -5,9 +5,12 @@ import { BitBucketOnPremInput, BitbucketOnPremRepoProps, BitbucketOnPremTreeInput, + BitbucketProperties, + BitbucketPropertiesInput, cacheFileTree, cancelCacheBitbucketTree, cleanBitbucketTreeCache, + getBitbucketProperties, getBranchesForRepoFromBitbucket, getCommitDetailsFromBitbucket, getCommitsForRepoFromBitbucket, @@ -263,7 +266,9 @@ export const resolvers = { branches: async (parent: any, { args }: BitBucketOnPremInput): Promise => getBranchesForRepoFromBitbucket(args), file: async (parent: any, { args }: BitBucketOnPremInput): Promise => - getFileContentFromBitbucket(args) + getFileContentFromBitbucket(args), + bitbucketProperties: async (parent: any, { args }: BitbucketPropertiesInput): Promise => + getBitbucketProperties(args) }, LangServerConfig: { allLangServerConfigs: async (parent: any): Promise => {