Skip to content

Commit

Permalink
When openedAt + TTL = now, consider the PR as expired (#4)
Browse files Browse the repository at this point in the history
* When openedAt + TTL = now, consider the PR as expired

* Build generation

---------

Co-authored-by: amegias <amegias@users.noreply.github.com>
  • Loading branch information
amegias and amegias committed Oct 25, 2023
1 parent 9dd17d0 commit eb5aa0a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 16 deletions.
103 changes: 91 additions & 12 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7288,7 +7288,7 @@ __export(dist_src_exports, {
module.exports = __toCommonJS(dist_src_exports);

// pkg/dist-src/version.js
var VERSION = "9.0.0";
var VERSION = "9.1.0";

// pkg/dist-src/normalize-paginated-list-response.js
function normalizePaginatedListResponse(response) {
Expand Down Expand Up @@ -7457,9 +7457,11 @@ var paginatingEndpoints = [
"GET /orgs/{org}/personal-access-tokens",
"GET /orgs/{org}/personal-access-tokens/{pat_id}/repositories",
"GET /orgs/{org}/projects",
"GET /orgs/{org}/properties/values",
"GET /orgs/{org}/public_members",
"GET /orgs/{org}/repos",
"GET /orgs/{org}/rulesets",
"GET /orgs/{org}/rulesets/rule-suites",
"GET /orgs/{org}/secret-scanning/alerts",
"GET /orgs/{org}/security-advisories",
"GET /orgs/{org}/teams",
Expand Down Expand Up @@ -7551,6 +7553,7 @@ var paginatingEndpoints = [
"GET /repos/{owner}/{repo}/releases/{release_id}/reactions",
"GET /repos/{owner}/{repo}/rules/branches/{branch}",
"GET /repos/{owner}/{repo}/rulesets",
"GET /repos/{owner}/{repo}/rulesets/rule-suites",
"GET /repos/{owner}/{repo}/secret-scanning/alerts",
"GET /repos/{owner}/{repo}/secret-scanning/alerts/{alert_number}/locations",
"GET /repos/{owner}/{repo}/security-advisories",
Expand Down Expand Up @@ -7682,7 +7685,7 @@ __export(dist_src_exports, {
module.exports = __toCommonJS(dist_src_exports);

// pkg/dist-src/version.js
var VERSION = "10.0.1";
var VERSION = "10.1.0";

// pkg/dist-src/generated/endpoints.js
var Endpoints = {
Expand Down Expand Up @@ -7787,6 +7790,9 @@ var Endpoints = {
enableWorkflow: [
"PUT /repos/{owner}/{repo}/actions/workflows/{workflow_id}/enable"
],
forceCancelWorkflowRun: [
"POST /repos/{owner}/{repo}/actions/runs/{run_id}/force-cancel"
],
generateRunnerJitconfigForOrg: [
"POST /orgs/{org}/actions/runners/generate-jitconfig"
],
Expand Down Expand Up @@ -8196,6 +8202,9 @@ var Endpoints = {
addSelectedRepoToOrgSecret: [
"PUT /orgs/{org}/codespaces/secrets/{secret_name}/repositories/{repository_id}"
],
checkPermissionsForDevcontainer: [
"GET /repos/{owner}/{repo}/codespaces/permissions_check"
],
codespaceMachinesForAuthenticatedUser: [
"GET /user/codespaces/{codespace_name}/machines"
],
Expand Down Expand Up @@ -8313,7 +8322,7 @@ var Endpoints = {
"DELETE /orgs/{org}/copilot/billing/selected_users"
],
getCopilotOrganizationDetails: ["GET /orgs/{org}/copilot/billing"],
getCopilotSeatAssignmentDetailsForUser: [
getCopilotSeatDetailsForUser: [
"GET /orgs/{org}/members/{username}/copilot"
],
listCopilotSeats: ["GET /orgs/{org}/copilot/billing/seats"]
Expand Down Expand Up @@ -8526,7 +8535,13 @@ var Endpoints = {
root: ["GET /"]
},
migrations: {
cancelImport: ["DELETE /repos/{owner}/{repo}/import"],
cancelImport: [
"DELETE /repos/{owner}/{repo}/import",
{},
{
deprecated: "octokit.rest.migrations.cancelImport() is deprecated, see https://docs.github.com/rest/migrations/source-imports#cancel-an-import"
}
],
deleteArchiveForAuthenticatedUser: [
"DELETE /user/migrations/{migration_id}/archive"
],
Expand All @@ -8539,9 +8554,27 @@ var Endpoints = {
getArchiveForAuthenticatedUser: [
"GET /user/migrations/{migration_id}/archive"
],
getCommitAuthors: ["GET /repos/{owner}/{repo}/import/authors"],
getImportStatus: ["GET /repos/{owner}/{repo}/import"],
getLargeFiles: ["GET /repos/{owner}/{repo}/import/large_files"],
getCommitAuthors: [
"GET /repos/{owner}/{repo}/import/authors",
{},
{
deprecated: "octokit.rest.migrations.getCommitAuthors() is deprecated, see https://docs.github.com/rest/migrations/source-imports#get-commit-authors"
}
],
getImportStatus: [
"GET /repos/{owner}/{repo}/import",
{},
{
deprecated: "octokit.rest.migrations.getImportStatus() is deprecated, see https://docs.github.com/rest/migrations/source-imports#get-an-import-status"
}
],
getLargeFiles: [
"GET /repos/{owner}/{repo}/import/large_files",
{},
{
deprecated: "octokit.rest.migrations.getLargeFiles() is deprecated, see https://docs.github.com/rest/migrations/source-imports#get-large-files"
}
],
getStatusForAuthenticatedUser: ["GET /user/migrations/{migration_id}"],
getStatusForOrg: ["GET /orgs/{org}/migrations/{migration_id}"],
listForAuthenticatedUser: ["GET /user/migrations"],
Expand All @@ -8555,18 +8588,42 @@ var Endpoints = {
{},
{ renamed: ["migrations", "listReposForAuthenticatedUser"] }
],
mapCommitAuthor: ["PATCH /repos/{owner}/{repo}/import/authors/{author_id}"],
setLfsPreference: ["PATCH /repos/{owner}/{repo}/import/lfs"],
mapCommitAuthor: [
"PATCH /repos/{owner}/{repo}/import/authors/{author_id}",
{},
{
deprecated: "octokit.rest.migrations.mapCommitAuthor() is deprecated, see https://docs.github.com/rest/migrations/source-imports#map-a-commit-author"
}
],
setLfsPreference: [
"PATCH /repos/{owner}/{repo}/import/lfs",
{},
{
deprecated: "octokit.rest.migrations.setLfsPreference() is deprecated, see https://docs.github.com/rest/migrations/source-imports#update-git-lfs-preference"
}
],
startForAuthenticatedUser: ["POST /user/migrations"],
startForOrg: ["POST /orgs/{org}/migrations"],
startImport: ["PUT /repos/{owner}/{repo}/import"],
startImport: [
"PUT /repos/{owner}/{repo}/import",
{},
{
deprecated: "octokit.rest.migrations.startImport() is deprecated, see https://docs.github.com/rest/migrations/source-imports#start-an-import"
}
],
unlockRepoForAuthenticatedUser: [
"DELETE /user/migrations/{migration_id}/repos/{repo_name}/lock"
],
unlockRepoForOrg: [
"DELETE /orgs/{org}/migrations/{migration_id}/repos/{repo_name}/lock"
],
updateImport: ["PATCH /repos/{owner}/{repo}/import"]
updateImport: [
"PATCH /repos/{owner}/{repo}/import",
{},
{
deprecated: "octokit.rest.migrations.updateImport() is deprecated, see https://docs.github.com/rest/migrations/source-imports#update-an-import"
}
]
},
orgs: {
addSecurityManagerTeam: [
Expand All @@ -8581,13 +8638,24 @@ var Endpoints = {
"PUT /orgs/{org}/outside_collaborators/{username}"
],
createInvitation: ["POST /orgs/{org}/invitations"],
createOrUpdateCustomProperties: ["PATCH /orgs/{org}/properties/schema"],
createOrUpdateCustomPropertiesValuesForRepos: [
"PATCH /orgs/{org}/properties/values"
],
createOrUpdateCustomProperty: [
"PUT /orgs/{org}/properties/schema/{custom_property_name}"
],
createWebhook: ["POST /orgs/{org}/hooks"],
delete: ["DELETE /orgs/{org}"],
deleteWebhook: ["DELETE /orgs/{org}/hooks/{hook_id}"],
enableOrDisableSecurityProductOnAllOrgRepos: [
"POST /orgs/{org}/{security_product}/{enablement}"
],
get: ["GET /orgs/{org}"],
getAllCustomProperties: ["GET /orgs/{org}/properties/schema"],
getCustomProperty: [
"GET /orgs/{org}/properties/schema/{custom_property_name}"
],
getMembershipForAuthenticatedUser: ["GET /user/memberships/orgs/{org}"],
getMembershipForUser: ["GET /orgs/{org}/memberships/{username}"],
getWebhook: ["GET /orgs/{org}/hooks/{hook_id}"],
Expand All @@ -8598,6 +8666,7 @@ var Endpoints = {
list: ["GET /organizations"],
listAppInstallations: ["GET /orgs/{org}/installations"],
listBlockedUsers: ["GET /orgs/{org}/blocks"],
listCustomPropertiesValuesForRepos: ["GET /orgs/{org}/properties/values"],
listFailedInvitations: ["GET /orgs/{org}/failed_invitations"],
listForAuthenticatedUser: ["GET /user/orgs"],
listForUser: ["GET /users/{username}/orgs"],
Expand All @@ -8622,6 +8691,9 @@ var Endpoints = {
redeliverWebhookDelivery: [
"POST /orgs/{org}/hooks/{hook_id}/deliveries/{delivery_id}/attempts"
],
removeCustomProperty: [
"DELETE /orgs/{org}/properties/schema/{custom_property_name}"
],
removeMember: ["DELETE /orgs/{org}/members/{username}"],
removeMembershipForUser: ["DELETE /orgs/{org}/memberships/{username}"],
removeOutsideCollaborator: [
Expand Down Expand Up @@ -9102,6 +9174,7 @@ var Endpoints = {
getCustomDeploymentProtectionRule: [
"GET /repos/{owner}/{repo}/environments/{environment_name}/deployment_protection_rules/{protection_rule_id}"
],
getCustomPropertiesValues: ["GET /repos/{owner}/{repo}/properties/values"],
getDeployKey: ["GET /repos/{owner}/{repo}/keys/{key_id}"],
getDeployment: ["GET /repos/{owner}/{repo}/deployments/{deployment_id}"],
getDeploymentBranchPolicy: [
Expand All @@ -9115,6 +9188,8 @@ var Endpoints = {
],
getLatestPagesBuild: ["GET /repos/{owner}/{repo}/pages/builds/latest"],
getLatestRelease: ["GET /repos/{owner}/{repo}/releases/latest"],
getOrgRuleSuite: ["GET /orgs/{org}/rulesets/rule-suites/{rule_suite_id}"],
getOrgRuleSuites: ["GET /orgs/{org}/rulesets/rule-suites"],
getOrgRuleset: ["GET /orgs/{org}/rulesets/{ruleset_id}"],
getOrgRulesets: ["GET /orgs/{org}/rulesets"],
getPages: ["GET /repos/{owner}/{repo}/pages"],
Expand All @@ -9130,6 +9205,10 @@ var Endpoints = {
getRelease: ["GET /repos/{owner}/{repo}/releases/{release_id}"],
getReleaseAsset: ["GET /repos/{owner}/{repo}/releases/assets/{asset_id}"],
getReleaseByTag: ["GET /repos/{owner}/{repo}/releases/tags/{tag}"],
getRepoRuleSuite: [
"GET /repos/{owner}/{repo}/rulesets/rule-suites/{rule_suite_id}"
],
getRepoRuleSuites: ["GET /repos/{owner}/{repo}/rulesets/rule-suites"],
getRepoRuleset: ["GET /repos/{owner}/{repo}/rulesets/{ruleset_id}"],
getRepoRulesets: ["GET /repos/{owner}/{repo}/rulesets"],
getStatusChecksProtection: [
Expand Down Expand Up @@ -49962,7 +50041,7 @@ const pullRequestExpiration = (environment, pullRequest, openedAt) => {
const interval = luxon_1.Interval.fromDateTimes(openedAt, now);
const diffInSeconds = interval.length('seconds');
const matched = (0, get_ttl_1.getTTL)(environment, pullRequest.labels);
const isExpired = diffInSeconds !== Number.MAX_VALUE && diffInSeconds > matched.ttl;
const isExpired = diffInSeconds !== Number.MAX_VALUE && diffInSeconds >= matched.ttl;
let result;
if (isExpired) {
const expiredResult = {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/helpers/__tests__/pull-request-expiration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ describe('pullRequestExpiration', () => {
false
],
[
`TTL equal to interval between now and openedAt returns not-expired`,
`TTL equal to interval between now and openedAt returns expired`,
DateTime.fromISO('2023-01-26T00:00:00Z'),
86400 /* 1d */,
false
true
],
[
`TTL less than interval between now and openedAt returns expired`,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/pull-request-expiration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const pullRequestExpiration = (
const diffInSeconds = interval.length('seconds');
const matched = getTTL(environment, pullRequest.labels);
const isExpired =
diffInSeconds !== Number.MAX_VALUE && diffInSeconds > matched.ttl;
diffInSeconds !== Number.MAX_VALUE && diffInSeconds >= matched.ttl;

let result: ExpirationResult;
if (isExpired) {
Expand Down

0 comments on commit eb5aa0a

Please sign in to comment.