Skip to content

Commit f6b8362

Browse files
authored
Merge pull request #273 from github/repo-sync
repo sync
2 parents 3d05341 + 7c0c493 commit f6b8362

File tree

10 files changed

+834
-306
lines changed

10 files changed

+834
-306
lines changed

content/packages/using-github-packages-with-your-projects-ecosystem/configuring-gradle-for-use-with-github-packages.md

+30-30
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,32 @@ publishing {
120120

121121
##### Example using Kotlin DSL for multiple packages in the same repository
122122

123-
```shell
124-
plugins {
125-
`maven-publish` apply false
126-
}
127-
128-
subprojects {
129-
apply(plugin = "maven-publish")
130-
configure<PublishingExtension> {
131-
repositories {
132-
maven {
133-
name = "GitHubPackages"
134-
url = uri("https://{% if currentVersion == "free-pro-team@latest" %}maven.pkg.github.com{% else %}<em>REGISTRY-URL</em>{% endif %}/<em>OWNER</em>/<em>REPOSITORY</em>")
135-
credentials {
136-
username = project.findProperty("gpr.user") as String? ?: System.getenv("<em>USERNAME</em>")
137-
password = project.findProperty("gpr.key") as String? ?: System.getenv("<em>TOKEN</em>")
138-
}
139-
}
140-
}
141-
publications {
142-
register<MavenPublication>("gpr") {
143-
from(components["java"])
144-
}
145-
}
146-
}
147-
}
148-
```
123+
```shell
124+
plugins {
125+
`maven-publish` apply false
126+
}
127+
128+
subprojects {
129+
apply(plugin = "maven-publish")
130+
configure<PublishingExtension> {
131+
repositories {
132+
maven {
133+
name = "GitHubPackages"
134+
url = uri("https://{% if currentVersion == "free-pro-team@latest" %}maven.pkg.github.com{% else %}<em>REGISTRY-URL</em>{% endif %}/<em>OWNER</em>/<em>REPOSITORY</em>")
135+
credentials {
136+
username = project.findProperty("gpr.user") as String? ?: System.getenv("<em>USERNAME</em>")
137+
password = project.findProperty("gpr.key") as String? ?: System.getenv("<em>TOKEN</em>")
138+
}
139+
}
140+
}
141+
publications {
142+
register<MavenPublication>("gpr") {
143+
from(components["java"])
144+
}
145+
}
146+
}
147+
}
148+
```
149149

150150
#### Authenticating with the `GITHUB_TOKEN`
151151

@@ -176,13 +176,13 @@ You can install a package by adding the package as a dependency to your project.
176176
Example using Grady Groovy:
177177
```shell
178178
dependencies {
179-
implementation 'com.example:package'
179+
implementation 'com.example:package'
180180
}
181181
```
182182
Example using Kotlin DSL:
183183
```shell
184184
dependencies {
185-
implementation("com.example:package")
185+
implementation("com.example:package")
186186
}
187187
```
188188

@@ -191,13 +191,13 @@ You can install a package by adding the package as a dependency to your project.
191191
Example using Grady Groovy:
192192
```shell
193193
plugins {
194-
id 'maven'
194+
id 'maven'
195195
}
196196
```
197197
Example using Kotlin DSL:
198198
```shell
199199
plugins {
200-
`maven`
200+
`maven`
201201
}
202202
```
203203

javascripts/events.js

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/* eslint-disable camelcase */
2+
import { v4 as uuidv4 } from 'uuid'
3+
import Cookies from 'js-cookie'
4+
import getCsrf from './get-csrf'
5+
6+
const COOKIE_NAME = '_docs-events'
7+
8+
let cookieValue
9+
10+
export function getUserEventsId () {
11+
if (cookieValue) return cookieValue
12+
cookieValue = Cookies.get(COOKIE_NAME)
13+
if (cookieValue) return cookieValue
14+
cookieValue = uuidv4()
15+
Cookies.set(COOKIE_NAME, cookieValue, {
16+
secure: true,
17+
sameSite: 'strict',
18+
expires: 365
19+
})
20+
return cookieValue
21+
}
22+
23+
export async function sendEvent ({
24+
type,
25+
version = '1.0.0',
26+
page_render_duration,
27+
exit_page_id,
28+
exit_first_paint,
29+
exit_dom_interactive,
30+
exit_dom_complete,
31+
exit_visit_duration,
32+
exit_scroll_length,
33+
link_url,
34+
search_query,
35+
search_context,
36+
navigate_label,
37+
survey_vote,
38+
survey_comment,
39+
survey_email,
40+
experiment_name,
41+
experiment_variation,
42+
experiment_success
43+
}) {
44+
const response = await fetch('/events', {
45+
method: 'POST',
46+
headers: {
47+
'Content-Type': 'application/json',
48+
'CSRF-Token': getCsrf()
49+
},
50+
body: JSON.stringify({
51+
type, // One of page, exit, link, search, navigate, survey, experiment
52+
53+
context: {
54+
// Primitives
55+
event_id: uuidv4(),
56+
user: getUserEventsId(),
57+
version,
58+
created: new Date().toISOString(),
59+
60+
// Content information
61+
path: location.pathname,
62+
referrer: document.referrer,
63+
search: location.search,
64+
href: location.href,
65+
site_language: location.pathname.split('/')[1],
66+
67+
// Device information
68+
// os:
69+
// os_version:
70+
// browser:
71+
// browser_version:
72+
viewport_width: document.documentElement.clientWidth,
73+
viewport_height: document.documentElement.clientHeight,
74+
75+
// Location information
76+
timezone: new Date().getTimezoneOffset() / -60,
77+
user_language: navigator.language
78+
},
79+
80+
// Page event
81+
page_render_duration,
82+
83+
// Exit event
84+
exit_page_id,
85+
exit_first_paint,
86+
exit_dom_interactive,
87+
exit_dom_complete,
88+
exit_visit_duration,
89+
exit_scroll_length,
90+
91+
// Link event
92+
link_url,
93+
94+
// Search event
95+
search_query,
96+
search_context,
97+
98+
// Navigate event
99+
navigate_label,
100+
101+
// Survey event
102+
survey_vote,
103+
survey_comment,
104+
survey_email,
105+
106+
// Experiment event
107+
experiment_name,
108+
experiment_variation,
109+
experiment_success
110+
})
111+
})
112+
const data = response.ok ? await response.json() : {}
113+
return data
114+
}
115+
116+
export default async function initializeEvents () {
117+
await sendEvent({ type: 'page' })
118+
}

javascripts/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ import localization from './localization'
1414
import helpfulness from './helpfulness'
1515
import experiment from './experiment'
1616
import { fillCsrf } from './get-csrf'
17+
import initializeEvents from './events'
1718

18-
document.addEventListener('DOMContentLoaded', () => {
19+
document.addEventListener('DOMContentLoaded', async () => {
1920
displayPlatformSpecificContent()
2021
explorer()
2122
search()
@@ -27,7 +28,8 @@ document.addEventListener('DOMContentLoaded', () => {
2728
wrapCodeTerms()
2829
print()
2930
localization()
30-
fillCsrf()
31+
await fillCsrf() // this must complete before any POST calls
3132
helpfulness()
3233
experiment()
34+
initializeEvents()
3335
})

lib/hydro.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
const crypto = require('crypto')
22
const fetch = require('node-fetch')
33

4+
const SCHEMAS = {
5+
page: 'docs.v0.PageEvent',
6+
exit: 'docs.v0.ExitEvent',
7+
link: 'docs.v0.LinkEvent',
8+
search: 'docs.v0.SearchEvent',
9+
navigate: 'docs.v0.NavigateEvent',
10+
survey: 'docs.v0.SurveyEvent',
11+
experiment: 'docs.v0.ExperimentEvent'
12+
}
13+
414
module.exports = class Hydro {
5-
constructor ({ secret, endpoint }) {
15+
constructor ({ secret, endpoint } = {}) {
616
this.secret = secret || process.env.HYDRO_SECRET
717
this.endpoint = endpoint || process.env.HYDRO_ENDPOINT
18+
this.schemas = SCHEMAS
819
}
920

1021
/**
@@ -32,7 +43,13 @@ module.exports = class Hydro {
3243
* @param {[{ schema: string, value: any }]} events
3344
*/
3445
async publishMany (events) {
35-
const body = JSON.stringify({ events })
46+
const body = JSON.stringify({
47+
events: events.map(({ schema, value }) => ({
48+
schema,
49+
value: JSON.stringify(value), // We must double-encode the value property
50+
cluster: 'potomac' // We only have ability to publish externally to potomac cluster
51+
}))
52+
})
3653
const token = this.generatePayloadHmac(body)
3754

3855
return fetch(this.endpoint, {
@@ -41,7 +58,7 @@ module.exports = class Hydro {
4158
headers: {
4259
Authorization: `Hydro ${token}`,
4360
'Content-Type': 'application/json',
44-
'X-Hydro-App': 'docs'
61+
'X-Hydro-App': 'docs-production'
4562
}
4663
})
4764
}

0 commit comments

Comments
 (0)