Skip to content

Commit 318eeee

Browse files
authored
repo sync
2 parents c272389 + 80bdffe commit 318eeee

13 files changed

Lines changed: 167 additions & 235 deletions

File tree

data/graphql/ghae/schema.docs-ghae.graphql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3129,7 +3129,9 @@ type Commit implements GitObject & Node & Subscribable & UniformResourceLocatabl
31293129
additions: Int!
31303130

31313131
"""
3132-
The pull requests associated with a commit
3132+
The merged Pull Request that introduced the commit to the repository. If the
3133+
commit is not present in the default branch, additionally returns open Pull
3134+
Requests associated with the commit
31333135
"""
31343136
associatedPullRequests(
31353137
"""

data/graphql/schema.docs.graphql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3219,7 +3219,9 @@ type Commit implements GitObject & Node & Subscribable & UniformResourceLocatabl
32193219
additions: Int!
32203220

32213221
"""
3222-
The pull requests associated with a commit
3222+
The merged Pull Request that introduced the commit to the repository. If the
3223+
commit is not present in the default branch, additionally returns open Pull
3224+
Requests associated with the commit
32233225
"""
32243226
associatedPullRequests(
32253227
"""

lib/graphql/static/prerendered-objects.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

lib/graphql/static/schema-dotcom.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9081,7 +9081,7 @@
90819081
},
90829082
{
90839083
"name": "associatedPullRequests",
9084-
"description": "<p>The pull requests associated with a commit.</p>",
9084+
"description": "<p>The merged Pull Request that introduced the commit to the repository. If the\ncommit is not present in the default branch, additionally returns open Pull\nRequests associated with the commit.</p>",
90859085
"type": "PullRequestConnection",
90869086
"id": "pullrequestconnection",
90879087
"kind": "objects",

lib/graphql/static/schema-ghae.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8268,7 +8268,7 @@
82688268
},
82698269
{
82708270
"name": "associatedPullRequests",
8271-
"description": "<p>The pull requests associated with a commit.</p>",
8271+
"description": "<p>The merged Pull Request that introduced the commit to the repository. If the\ncommit is not present in the default branch, additionally returns open Pull\nRequests associated with the commit.</p>",
82728272
"type": "PullRequestConnection",
82738273
"id": "pullrequestconnection",
82748274
"kind": "objects",

lib/redis-accessor.js

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,21 @@
1-
const Redis = require('ioredis')
2-
const InMemoryRedis = require('ioredis-mock')
1+
const createRedisClient = require('./redis/create-client')
2+
const InMemoryRedis = require('redis-mock')
3+
const { promisify } = require('util')
34

4-
const { CI, NODE_ENV, REDIS_URL, REDIS_MAX_DB } = process.env
5+
const { CI, NODE_ENV, REDIS_URL } = process.env
56

67
// Do not use real a Redis client for CI, tests, or if the REDIS_URL is not provided
78
const useRealRedis = !CI && NODE_ENV !== 'test' && !!REDIS_URL
89

9-
// By default, every Redis instance supports database numbers 0 - 15
10-
const redisMaxDb = REDIS_MAX_DB || 15
11-
12-
// Enable better stack traces in non-production environments
13-
const redisBaseOptions = {
14-
showFriendlyErrorStack: NODE_ENV !== 'production'
15-
}
16-
1710
class RedisAccessor {
18-
constructor ({ databaseNumber = 0, prefix = null, allowSetFailures = false } = {}) {
19-
if (!Number.isInteger(databaseNumber) || databaseNumber < 0 || databaseNumber > redisMaxDb) {
20-
throw new TypeError(
21-
`Redis database number must be an integer between 0 and ${redisMaxDb} but was: ${JSON.stringify(databaseNumber)}`
22-
)
23-
}
24-
11+
constructor ({ databaseNumber = 0, prefix = null, allowSetFailures = false, name = null } = {}) {
2512
const redisClient = useRealRedis
26-
? new Redis(REDIS_URL, {
27-
...redisBaseOptions,
13+
? createRedisClient({
14+
url: REDIS_URL,
2815
db: databaseNumber,
29-
30-
// Only add this configuration for TLS-enabled REDIS_URL values.
31-
// Otherwise, it breaks for local Redis instances without TLS enabled.
32-
...REDIS_URL.startsWith('rediss://') && {
33-
tls: {
34-
// Required for production Heroku Redis
35-
rejectUnauthorized: false
36-
}
37-
}
16+
name: name || 'redis-accessor'
3817
})
39-
: new InMemoryRedis()
18+
: InMemoryRedis.createClient()
4019

4120
this._client = redisClient
4221

@@ -96,6 +75,7 @@ class RedisAccessor {
9675
}
9776

9877
async set (key, value, options = {}) {
78+
const setAsync = promisify(this._client.set).bind(this._client)
9979
const fullKey = this.prefix(key)
10080

10181
if (typeof value !== 'string' || !value) {
@@ -106,7 +86,7 @@ class RedisAccessor {
10686
const setArgs = this.constructor.translateSetArguments(options)
10787

10888
try {
109-
const result = await this._client.set(fullKey, value, ...setArgs)
89+
const result = await setAsync(fullKey, value, ...setArgs)
11090
return result === 'OK'
11191
} catch (err) {
11292
const errorText = `Failed to set value in Redis.
@@ -124,14 +104,10 @@ Error: ${err.message}`
124104
}
125105

126106
async get (key) {
127-
const value = await this._client.get(this.prefix(key))
107+
const getAsync = promisify(this._client.get).bind(this._client)
108+
const value = await getAsync(this.prefix(key))
128109
return value
129110
}
130-
131-
async exists (key) {
132-
const result = await this._client.exists(this.prefix(key))
133-
return result === 1
134-
}
135111
}
136112

137113
module.exports = RedisAccessor

lib/redis/create-client.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ const { REDIS_MIN_DB, REDIS_MAX_DB } = process.env
66
const redisMinDb = REDIS_MIN_DB || 0
77
const redisMaxDb = REDIS_MAX_DB || 15
88

9-
function formatRedisError (error = {}) {
10-
const { code } = error
11-
const preamble = error.constructor.name + (code ? ` with code "${code}"` : '')
12-
return preamble + error.toString()
9+
function formatRedisError (error) {
10+
const errorCode = error ? error.code : null
11+
const errorName = error ? error.constructor.name : 'Error'
12+
const errorMsg = error ? error.toString() : 'unknown error'
13+
const preamble = errorName + (errorCode ? ` with code "${errorCode}"` : '')
14+
return preamble + ': ' + errorMsg
1315
}
1416

1517
module.exports = function createClient (options = {}) {
@@ -45,7 +47,7 @@ module.exports = function createClient (options = {}) {
4547
})
4648

4749
// If a `name` was provided, use it in the prefix for logging event messages
48-
const logPrefix = '[redis' + (name ? ` (${name})` : '') + '] '
50+
const logPrefix = '[redis' + (name ? ` (${name})` : '') + ']'
4951

5052
// Add event listeners for basic logging
5153
client.on('connect', () => { console.log(logPrefix, 'Connection opened') })

middleware/render-page.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const pageCache = new RedisAccessor({
1616
databaseNumber: pageCacheDatabaseNumber,
1717
prefix: (HEROKU_RELEASE_VERSION ? HEROKU_RELEASE_VERSION + ':' : '') + 'rp',
1818
// Allow for graceful failures if a Redis SET operation fails
19-
allowSetFailures: true
19+
allowSetFailures: true,
20+
name: 'page-cache'
2021
})
2122

2223
// a list of query params that *do* alter the rendered page, and therefore should be cached separately

package-lock.json

Lines changed: 19 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)