-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from sliit-foss/development
Automatic versioning patch and leaderboard type support
- Loading branch information
Showing
9 changed files
with
191 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,4 +44,4 @@ | |
"node": ">=14.0.0" | ||
}, | ||
"packageManager": "pnpm@7.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[]>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
}); | ||
}); |