-
Notifications
You must be signed in to change notification settings - Fork 0
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 #56 from open-ish/feat/use-utility
feat: use utility on the name
- Loading branch information
Showing
8 changed files
with
287 additions
and
79 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
name: Merge and Close Dependabot PRs | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 2 * *' | ||
workflow_dispatch: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
merge-dependabot-prs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run merge-dependabot-prs | ||
run: | | ||
npx merge-dependabot-prs \ | ||
--repoUrl=https://github.com/open-ish/utility.git \ | ||
--combinedBranch=ci/combined-dependabot-updates \ | ||
--mainBranch=master \ | ||
--githubToken=${{ secrets.GH_TOKEN }} \ | ||
--repoOwner=open-ish \ | ||
--repoName=utility | ||
close-dependabot-prs: | ||
if: github.event.issue.pull_request && contains(github.event.comment.body, '[dependabot-pr-manager] close prs') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run close-dependabot-prs | ||
run: | | ||
npx close-dependabot-prs \ | ||
--githubToken=${{ secrets.GH_TOKEN }} \ | ||
--repoOwner=open-ish \ | ||
--repoName=utility |
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,11 +0,0 @@ | ||
# [1.2.0](https://github.com/open-ish/utility/compare/dependabot-pr-manager-v1.1.0...dependabot-pr-manager-v1.2.0) (2024-11-06) | ||
|
||
|
||
### Bug Fixes | ||
|
||
* use auth header on create pull ([6aabcef](https://github.com/open-ish/utility/commit/6aabcef8d7a9b8df58f25423834e17c58067fda0)) | ||
|
||
|
||
### Features | ||
|
||
* use lib right name ([7e489af](https://github.com/open-ish/utility/commit/7e489af3dd0ccc2ee1e139fa54ac686251688d26)) | ||
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,73 +1,90 @@ | ||
# http front cache | ||
# dependabot-pr-manager | ||
|
||
## Installation | ||
|
||
Install it on devDependencies. Ex: | ||
|
||
```bash | ||
npm i utility-http-front-cache | ||
npm i dependabot-pr-manager -D | ||
``` | ||
|
||
## Motivation | ||
|
||
1. The data to be cached is not too big. | ||
2. The data to be cached is not sensitive. | ||
3. The data to be cached does not change too often. | ||
4. The cache does not need to be updated based on user navigation (e.g., caching cart data is not recommended as the user can add more products and the cache will not be updated). | ||
5. The service parameters do not change too often (if they change too often, the cache will not be used). | ||
|
||
## How to Use | ||
`dependabot-pr-manager` is a utility to manage dependabot PRs. It groups DependaBot PRs on the repository and creates a PR with the updated dependencies. It is useful when you have multiple dependabot PRs and you want to merge them all at once. | ||
|
||
### Example | ||
### What does it do? | ||
|
||
```typescript | ||
import { cacheOnSessionStorage } from 'utility-http-front-cache'; | ||
dependabot-pr-manager has two main scripts: `merge-dependabot-pr` and `close-dependabot-prs`. | ||
|
||
type Params = [string]; | ||
type Result = { data: string[] }; | ||
- the `merge-dependabot-prs` groups all Dependabot PRs into a single PR. So, it do not merge it automatically, giving you the opportunity to review/update the changes before merging. | ||
- the `close-dependabot-prs` close all Dependabot prs | ||
|
||
const fetchData: ServiceFunction<Params, Result> = async (param: string) => { | ||
const response = await fetch(`https://api.example.com/data?param=${param}`); | ||
return response.json(); | ||
}; | ||
See the [How to Use](#how-to-use) section for more information on how to use the `dependabot-pr-manager` library in your CI pipeline. | ||
|
||
const cachedFetchData = cacheOnSessionStorage(fetchData, 5 * 60 * 1000); // Cache for 5 minutes | ||
## How to Use | ||
|
||
// Usage | ||
cachedFetchData('exampleParam').then((result) => { | ||
console.log(result); | ||
}); | ||
You can use the `dependabot-pr-manager` library in your CI pipeline to automatically manage and merge Dependabot PRs. Below is an example of how to set up a GitHub Action to run the `dependabot-pr-manager` script on the second day of every month and allow manual triggering via a GitHub button. Additionally, it includes a job to close the Dependabot PRs when the created PR is commented with "[dependabot-pr-manager] close prs". | ||
|
||
file example: .github/workflows/dependabot-pr-manager.yml | ||
|
||
```yaml | ||
name: Merge and Close Dependabot PRs | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 2 * *' # Runs at 00:00 on the 2nd day of every month, so if your dependabot runs monthly in the first day, all PRs will be merged on the second day. Change to fit your needs. | ||
workflow_dispatch: # Allows manual triggering via GitHub button | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
merge-dependabot-prs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run merge-dependabot-prs | ||
run: | | ||
npx merge-dependabot-prs \ | ||
--repoUrl=https://github.com/open-ish/utility.git \ | ||
--combinedBranch=ci/combined-dependabot-update \ | ||
--mainBranch=main \ | ||
--githubToken=${{ secrets.YOUR_GIT_HUB_TOKEN }} \ | ||
--repoOwner=open-ish \ | ||
--repoName=utility | ||
close-dependabot-prs: | ||
if: github.event.issue.pull_request && contains(github.event.comment.body, '[dependabot-pr-manager] close prs') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '14' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run close-dependabot-prs | ||
run: | | ||
npx close-dependabot-prs \ | ||
--repoUrl=https://github.com/open-ish/utility.git \ | ||
--githubToken=${{ secrets.YOUR_GIT_HUB_TOKEN }} \ | ||
--repoOwner=open-ish \ | ||
--repoName=utility | ||
``` | ||
## Another Storage | ||
|
||
Currently, the `cacheOnSessionStorage` utility only supports [session storage as provider](https://github.com/open-ish/utility/blob/c6d98898bbc6119cd482b736f57ec897443e71de/packages/http-front-cache/src/lib/providers/session-storage.ts#L1-L8). However, it can be easily extended to support other storage mechanisms such as local storage or indexedDB by using the `cacheFactory` function. | ||
|
||
```typescript | ||
import { cacheFactory, ServiceFunction } from 'utility-http-front-cache'; | ||
|
||
const customProvider = { | ||
getItem: (key: string) => Uint8Array; // cacheFactory converts the result from serviceFunction on UInt8Array, so you can assumes that the data returned on getItem is always a UInt8Array. Example of provider here https://github.com/open-ish/utility/blob/c6d98898bbc6119cd482b736f57ec897443e71de/packages/http-front-cache/src/lib/providers/session-storage.ts#L1-L8 | ||
setItem: (key: string, value: Uint8Array) => void; | ||
removeItem: (key: string) => void; | ||
}; | ||
|
||
export const cacheOnMyCustomProvider = <TParams extends unknown[], TResult>( | ||
serviceFunction: ServiceFunction<TParams, TResult>, | ||
expire: number | ||
): ServiceFunction<TParams, TResult> => { | ||
return async (...params: TParams): Promise<TResult> => { | ||
return cacheFactory<TParams, TResult>({ | ||
params, | ||
expire, | ||
serviceFunction: fetchData, | ||
provider: customProvider, | ||
}); | ||
}; | ||
}; | ||
|
||
// usage | ||
const cachedFetchData = cacheOnMyCustomProvider(fetchData, 5 * 60 * 1000); // Cache for 5 minutes | ||
|
||
cachedFetchData('exampleParam').then((result) => { | ||
console.log(result); | ||
}); | ||
|
||
|
||
``` | ||
- merge-dependabot-prs Job: This job runs the merge-dependabot-prs script to group and merge Dependabot PRs. | ||
- close-dependabot-prs Job: This job runs the close-dependabot-prs script to close the Dependabot PRs when the pull request created from dependabot-pr-manager be commented with `'[dependabot-pr-manager] close prs'`. |
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 +1,2 @@ | ||
export * from './lib/script.mjs'; | ||
export * from './lib/merge-dependabot-prs.mjs'; | ||
export * from './lib/close-dependabot-prs.mjs'; |
Oops, something went wrong.