@shelf/gh-sdk
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -12,4 +12,10 @@ import type { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods'; | ||
export declare function listPrs(params: ListOpenPRsParams): ReturnType<typeof getPRs>; | ||
export declare function getOpenRepoPRsFromHuman(owner: string, repo: string): Promise<any[]>; | ||
export declare function getCommitChecks(owner: string, repo: string, commitRef: string): Promise<any[]>; | ||
export declare function getPRCommitRefsWithMessages(owner: string, repo: string, prNumber: number): Promise<{ | ||
sha: string; | ||
message: string; | ||
}[]>; | ||
export declare function listClosedPRs(params: ListOpenPRsParams): ReturnType<typeof getPRs>; | ||
declare function getPRs(params: ListPRsParams): Promise<RestEndpointMethodTypes['search']['issuesAndPullRequests']['response']['data']['items']>; | ||
export {}; |
@@ -6,2 +6,5 @@ "use strict"; | ||
}); | ||
exports.getCommitChecks = getCommitChecks; | ||
exports.getOpenRepoPRsFromHuman = getOpenRepoPRsFromHuman; | ||
exports.getPRCommitRefsWithMessages = getPRCommitRefsWithMessages; | ||
exports.listClosedPRs = listClosedPRs; | ||
@@ -16,2 +19,42 @@ exports.listPrs = listPrs; | ||
} | ||
async function getOpenRepoPRsFromHuman(owner, repo) { | ||
const gh = (0, _restClient.getClient)(); | ||
const { | ||
data | ||
} = await gh.pulls.list({ | ||
owner, | ||
repo, | ||
state: 'open' | ||
}); | ||
return data.filter(pr => { | ||
var _pr$user; | ||
return !(pr !== null && pr !== void 0 && (_pr$user = pr.user) !== null && _pr$user !== void 0 && _pr$user.login.endsWith('[bot]')) && !pr.draft; | ||
}); | ||
} | ||
async function getCommitChecks(owner, repo, commitRef) { | ||
const gh = (0, _restClient.getClient)(); | ||
const { | ||
data | ||
} = await gh.request({ | ||
method: 'GET', | ||
url: `/repos/${owner}/${repo}/commits/${commitRef}/statuses` | ||
}); | ||
return data; | ||
} | ||
async function getPRCommitRefsWithMessages(owner, repo, prNumber) { | ||
const gh = (0, _restClient.getClient)(); | ||
const { | ||
data | ||
} = await gh.pulls.listCommits({ | ||
owner, | ||
repo, | ||
pull_number: prNumber | ||
}); | ||
return data.map(commit => { | ||
return { | ||
sha: commit.sha, | ||
message: commit.commit.message | ||
}; | ||
}); | ||
} | ||
function listClosedPRs(params) { | ||
@@ -18,0 +61,0 @@ return getPRs({ |
{ | ||
"name": "@shelf/gh-sdk", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Convenient wrapper for GitHub API for automation tasks", | ||
@@ -51,3 +51,3 @@ "license": "MIT", | ||
"@babel/cli": "7.19.3", | ||
"@babel/core": "7.20.5", | ||
"@babel/core": "7.21.4", | ||
"@shelf/babel-config": "1.2.0", | ||
@@ -57,11 +57,11 @@ "@shelf/eslint-config": "2.26.0", | ||
"@shelf/tsconfig": "0.0.9", | ||
"@types/jest": "29.2.4", | ||
"@types/lodash": "4.14.191", | ||
"@types/jest": "29.5.1", | ||
"@types/lodash": "4.14.194", | ||
"@types/node": "16", | ||
"eslint": "8.29.0", | ||
"eslint": "8.40.0", | ||
"husky": "8.0.2", | ||
"jest": "29.3.1", | ||
"lint-staged": "13.1.0", | ||
"prettier": "2.8.1", | ||
"typescript": "4.9.4" | ||
"jest": "29.5.0", | ||
"lint-staged": "13.2.2", | ||
"prettier": "2.8.8", | ||
"typescript": "4.9.5" | ||
}, | ||
@@ -68,0 +68,0 @@ "engines": { |
@@ -44,2 +44,5 @@ # gh-sdk [![CircleCI](https://circleci.com/gh/shelfio/gh-sdk/tree/master.svg?style=svg)](https://circleci.com/gh/shelfio/gh-sdk/tree/master)![](https://img.shields.io/badge/code_style-prettier-ff69b4.svg) | ||
}); | ||
getOpenRepoPRsFromHuman('shelf', 'repo'); | ||
getCommitChecks('shelf', 'repo', 'sha'); | ||
getPRCommitRefsWithMessages('shelf', 'repo', 3); | ||
``` | ||
@@ -46,0 +49,0 @@ |
29391
807
61