Skip to content

Commit

Permalink
Bitbucket On Prem - Support Fetching Instance Version (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
Urook committed Mar 7, 2023
1 parent 0d17a41 commit 497cfba
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
12 changes: 12 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ input BitbucketTreeInput {
maxResults: Int
}

input BitbucketPropertiesInput {
url: String!
}

enum SupportedServerLanguage {
java
python
Expand Down Expand Up @@ -124,6 +128,7 @@ type BitbucketOnPrem {
commit(args: BitbucketInput!): BitbucketCommit
branches(args: BitbucketInput!): [BitbucketBranch]
file(args: BitbucketInput!): String
bitbucketProperties(args: BitbucketPropertiesInput!): BitbucketProperties
}

type BitbucketUser {
Expand Down Expand Up @@ -177,6 +182,13 @@ type BitbucketBranch {
isDefault: Boolean!
}

type BitbucketProperties {
version: String
buildNumber: String
buildDate: String
displayName: String
}

type Log {
level: String!
time: String!
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
31 changes: 31 additions & 0 deletions src/BitBucketOnPrem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export interface BitbucketOnPremRepoProps {
maxResults?: number;
}

export interface BitbucketOnPremPropertiesInputProps {
url: string;
}

export interface BitBucketOnPremInput {
args: BitbucketOnPrem;
}
Expand All @@ -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}`;
};
Expand Down Expand Up @@ -506,6 +521,22 @@ export const getCommitDetailsFromBitbucket = async ({url, accessToken, projectKe
return res.json();
};

export const getBitbucketProperties =
async ({url}: BitbucketOnPremPropertiesInputProps): Promise<BitbucketProperties> => {

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;
Expand Down
7 changes: 6 additions & 1 deletion src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import {
BitBucketOnPremInput,
BitbucketOnPremRepoProps,
BitbucketOnPremTreeInput,
BitbucketProperties,
BitbucketPropertiesInput,
cacheFileTree,
cancelCacheBitbucketTree,
cleanBitbucketTreeCache,
getBitbucketProperties,
getBranchesForRepoFromBitbucket,
getCommitDetailsFromBitbucket,
getCommitsForRepoFromBitbucket,
Expand Down Expand Up @@ -263,7 +266,9 @@ export const resolvers = {
branches: async (parent: any, { args }: BitBucketOnPremInput): Promise<any> =>
getBranchesForRepoFromBitbucket(args),
file: async (parent: any, { args }: BitBucketOnPremInput): Promise<string> =>
getFileContentFromBitbucket(args)
getFileContentFromBitbucket(args),
bitbucketProperties: async (parent: any, { args }: BitbucketPropertiesInput): Promise<BitbucketProperties> =>
getBitbucketProperties(args)
},
LangServerConfig: {
allLangServerConfigs: async (parent: any): Promise<LangServerConfig[]> => {
Expand Down

0 comments on commit 497cfba

Please sign in to comment.