Skip to content

Commit

Permalink
Merge pull request #120 from sliit-foss/development
Browse files Browse the repository at this point in the history
Automatic versioning patch and leaderboard type support
  • Loading branch information
Akalanka47000 authored Dec 3, 2023
2 parents c766913 + 4859b7e commit 141bf54
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
"node": ">=14.0.0"
},
"packageManager": "pnpm@7.5.0"
}
}
2 changes: 1 addition & 1 deletion packages/automatic-versioning/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/automatic-versioning",
"version": "1.4.6",
"version": "1.4.7-blizzard.0",
"description": "A script which will automatically increment your app package version in accordance with conventional commits",
"main": "dist/index.js",
"bin": "dist/index.js",
Expand Down
22 changes: 15 additions & 7 deletions packages/automatic-versioning/src/types/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ const runner = (name, noCommit, noCommitEdit, recursive = false, prereleaseTag,
const currentBranch = (await run("git rev-parse --abbrev-ref HEAD"))?.trim();
if (currentBranch === prereleaseBranch) {
let prerelease = false;
const currentVersion = (
await run(`npm view ${name} time`)
.then((res) => res?.split(",")?.pop()?.split(":")?.[0])
.catch(async () => (await run("npm version"))?.split(",")?.[0]?.split(":")?.[1])
)
?.replace(/[{}'']/g, "")
?.trim();
let currentVersion;
try {
const versions = await run(`npm view ${name} time`).then((res) =>
res
.replace(/{|}|,|'/g, "")
.trim()
.split("\n")
);
versions.sort(
(v1, v2) => new Date(v1.trim().split(" ")[1]).getTime() - new Date(v2.trim().split(" ")[1]).getTime()
);
currentVersion = versions.pop().split(":")?.[0].trim();
} catch (e) {
currentVersion = (await run("npm version"))?.split(",")?.[0]?.split(":")?.[1]?.replace(/'/g, "")?.trim();
}
if (currentVersion?.includes(prereleaseTag)) {
await run(
`npm --workspaces-update=false --no-git-tag-version version --allow-same-version ${currentVersion}`
Expand Down
3 changes: 2 additions & 1 deletion packages/leaderboard/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "@sliit-foss/leaderboard",
"version": "1.1.1",
"version": "1.2.0-blizzard.0",
"description": "A utility package for fetching a list of contributor scores to a GitHub organization or repository",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
Expand Down
70 changes: 70 additions & 0 deletions packages/leaderboard/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
type LeaderboardRecord = {
url: string;
login: string;
points: number;
};

/**
* Initializes the necessary headers for API requests to the GitHub API using the Axios HTTP client.
* This function should be called before fetching the leaderboards.
*
* @param {string} token - The token used for authorization. It should be a valid access token for the GitHub API.
* It is important to ensure that you have a valid access token with the required permissions
* to access the GitHub API before calling the `initialize` function.
*
* @example
* ```typescript
* import leaderboard from '@sliit-foss/leaderboard';
*
* leaderboard.initialize("GITHUB_ACCESS_TOKEN");
*
* // Now you can fetch the leaderboards
* ```
*/
export function initialize(token: string): void;

/**
* Fetches the leaderboard for one or more organizations.
*
* @param {object} options - Options for fetching the leaderboard.
* @param {(string|string[])} options.orgs - The name(s) of the organization(s) to fetch the leaderboard for.
* @param {object} [options.filters={}] - Additional filters to apply.
* @param {string} [options.filters.between] - A date range in the format "start..end" to filter the pull requests.
* @param {string} [options.filters.label] - A label to filter the pull requests.
* @param {number} [options.filters.pageSize] - The number of results per page to retrieve.
* @param {number} [options.filters.pageLimit] - The maximum number of pages to fetch.
* @returns {Promise<LeaderboardRecord[]>} A promise that resolves to an array of leaderboard records.
*/
export function getOrganizationLeaderboard(options: {
orgs: string | string[];
filters?: {
between?: string;
label?: string;
pageSize?: number;
pageLimit?: number;
};
}): Promise<LeaderboardRecord[]>;

/**
* Fetches the leaderboard for a specific repository.
*
* @param {object} options - Options for fetching the leaderboard.
* @param {string} options.owner - The owner of the repository.
* @param {string} options.repository - The name of the repository.
* @param {object} [options.filters={}] - Additional filters to apply.
* @param {string} [options.filters.between] - A date range in the format "start..end" to filter the pull requests.
* @param {string} [options.filters.label] - A label to filter the pull requests.
* @param {number} [options.filters.pageSize] - The number of results per page to retrieve.
* @param {number} [options.filters.pageLimit] - The maximum number of pages to fetch.
* @returns {Promise<LeaderboardRecord[]>} A promise that resolves to an array of leaderboard records.
*/
export function getRepositoryLeaderboard(options: {
owner: string;
repository: string;
filters?: {
between?: string;
label?: string;
pageSize?: number;
pageLimit?: number;
};
}): Promise<LeaderboardRecord[]>;
1 change: 1 addition & 0 deletions packages/module-logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.1.5",
"description": "A modularized logger wrapped around winston to make working with nodeJS microservices easier.",
"main": "dist/index.js",
"types": "types/index.d.ts",
"scripts": {
"build": "node ../../scripts/esbuild.config.js",
"build:watch": "bash ../../scripts/esbuild.watch.sh",
Expand Down
23 changes: 23 additions & 0 deletions packages/module-logger/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Logger } from "winston";
declare interface Config {
transportOverrides?: any;
console?: {
enabled: boolean;
options?: any;
};
file?: {
enabled: boolean;
options?: any;
};
globalAttributes?: any;
}

/**
* Configures the module logger with a given user configuration.
*/
export function configure(userConfig: Config): void;

/**
* Returns a modularized logger instance for a given module name.
*/
export function moduleLogger(moduleName?: string): Logger;
2 changes: 1 addition & 1 deletion plugins/babel-plugin-transform-trace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bump-version": "bash ../../scripts/bump-version.sh --name=@sliit-foss/babel-plugin-transform-trace",
"lint": "bash ../../scripts/lint.sh",
"release": "bash ../../scripts/release.sh",
"test": "dotenv -- jest --coverage --verbose --runInBand --forceExit"
"test": "bash ../../scripts/test/test.sh"
},
"keywords": [
"babel-plugin",
Expand Down
79 changes: 77 additions & 2 deletions plugins/babel-plugin-transform-trace/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,80 @@
const { transform } = require("@babel/core");
const plugin = require("../src/index");

const ignoreWhiteSpaces = (str) => str.replace(/\s/g, "");

const transformCode = (code, ignore = [], clean = false) => {
return ignoreWhiteSpaces(
transform(code, {
plugins: [
[
plugin,
{
"ignore-functions": ignore,
clean: clean
}
]
]
}).code
);
};

describe("babel-plugin-transform-trace", () => {
it("should work", () => {
expect(true).toBe(true);
it("should add import statement if not present", () => {
const expectedCode = `var { traced } = require('@sliit-foss/functions');`;
expect(transformCode(``)).toBe(ignoreWhiteSpaces(expectedCode));
});
it("should not add import statement if it's already present", () => {
const code = `var { traced, trace } = require('@sliit-foss/functions');`;
expect(transformCode(code)).toBe(ignoreWhiteSpaces(code));
});
it("should transform function calls", () => {
const code = `
function foo() {
bar();
}
`;
const expectedCode = `
var { traced } = require('@sliit-foss/functions');
function foo() {
traced(bar)();
}
`;
expect(transformCode(code)).toBe(ignoreWhiteSpaces(expectedCode));
});

it("should skip exluded function calls", () => {
const code = `
function foo() {
bar();
baz();
}
`;
const expectedCode = `
var { traced } = require('@sliit-foss/functions') ;
function foo() {
traced(bar)();
baz();
}
`;
expect(transformCode(code, ["baz"])).toBe(ignoreWhiteSpaces(expectedCode));
});

it("should use cleanTraced if option is true", () => {
const code = `
function foo() {
bar();
}
`;
const expectedCode = `
var { cleanTraced } = require('@sliit-foss/functions') ;
function foo() {
cleanTraced(bar)();
}
`;
expect(transformCode(code, [], true)).toBe(ignoreWhiteSpaces(expectedCode));
});
});

0 comments on commit 141bf54

Please sign in to comment.