@posthog/bitbucket-release-tracker
Advanced tools
Comparing version 0.0.2 to 0.0.3
58
index.js
@@ -1,3 +0,3 @@ | ||
async function setupPlugin({ config, global }) { | ||
let bitbucketBase64AuthToken; | ||
export async function setupPlugin({ config, global }) { | ||
let bitbucketBase64AuthToken | ||
@@ -7,3 +7,3 @@ if (config.bitbucketUsername && config.bitbucketToken) { | ||
'base64' | ||
); | ||
) | ||
} else if (config.bitbucketUsername || config.bitbucketToken) { | ||
@@ -21,3 +21,3 @@ throw new Error( | ||
} | ||
: {}; | ||
: {} | ||
@@ -28,15 +28,15 @@ global.posthogOptions = { | ||
} | ||
}; | ||
} | ||
config.posthogHost = config.posthogHost.replace(/\/$/, ''); | ||
config.bitbucketHost = config.bitbucketHost.replace(/\/$/, ''); | ||
config.posthogHost = config.posthogHost.replace(/\/$/, '') | ||
config.bitbucketHost = config.bitbucketHost.replace(/\/$/, '') | ||
global.posthogHost = config.posthogHost.includes('http') ? config.posthogHost : 'https://' + config.posthogHost; | ||
global.posthogHost = config.posthogHost.includes('http') ? config.posthogHost : 'https://' + config.posthogHost | ||
global.bitbucketApiBaseUrl = | ||
(config.bitbucketHost.includes('http') ? config.bitbucketHost : 'https://' + config.bitbucketHost) + | ||
`/api/2.0/repositories/${config.bitbucketWorkspace}/${config.repoName}`; | ||
`/api/2.0/repositories/${config.bitbucketWorkspace}/${config.repoName}` | ||
try { | ||
const posthogRes = await fetchWithRetry(`${global.posthogHost}/api/users/@me`, global.posthogOptions); | ||
const posthogRes = await fetchWithRetry(`${global.posthogHost}/api/users/@me`, global.posthogOptions) | ||
if (posthogRes.status !== 200) { | ||
@@ -46,3 +46,3 @@ throw new Error('Invalid PostHog Personal API key') | ||
const bitbucketRes = await fetchWithRetry(global.bitbucketApiBaseUrl, global.bitbucketAuthHeader); | ||
const bitbucketRes = await fetchWithRetry(global.bitbucketApiBaseUrl, global.bitbucketAuthHeader) | ||
if (bitbucketRes.status !== 200) { | ||
@@ -56,4 +56,4 @@ throw new Error('Unable to connect to Bitbucket - Invalid Bitbucket host, workspace, repo name, or token') | ||
async function runEveryMinute({ config, global, cache }) { | ||
const lastRun = await cache.get('lastRun'); | ||
export async function runEveryMinute({ config, global, cache }) { | ||
const lastRun = await cache.get('lastRun') | ||
if ( | ||
@@ -65,13 +65,13 @@ lastRun && | ||
} | ||
let allPostHogAnnotations = []; | ||
let next = `${global.posthogHost}/api/annotation/?scope=organization&deleted=false`; | ||
let allPostHogAnnotations = [] | ||
let next = `${global.posthogHost}/api/annotation/?scope=organization&deleted=false` | ||
while (next) { | ||
const annotationsResponse = await fetchWithRetry(next, global.posthogOptions); | ||
const annotationsJson = await annotationsResponse.json(); | ||
const annotationNames = annotationsJson.results.map((annotation) => annotation.content); | ||
next = annotationsJson.next; | ||
allPostHogAnnotations = [...allPostHogAnnotations, ...annotationNames]; | ||
const annotationsResponse = await fetchWithRetry(next, global.posthogOptions) | ||
const annotationsJson = await annotationsResponse.json() | ||
const annotationNames = annotationsJson.results.map((annotation) => annotation.content) | ||
next = annotationsJson.next | ||
allPostHogAnnotations = [...allPostHogAnnotations, ...annotationNames] | ||
} | ||
let annotations = new Set(allPostHogAnnotations); | ||
let annotations = new Set(allPostHogAnnotations) | ||
@@ -81,5 +81,5 @@ const bitbucketTagsResponse = await fetchWithRetry( | ||
global.bitbucketAuthHeader | ||
); | ||
) | ||
const bitbucketTagsJson = await bitbucketTagsResponse.json(); | ||
const bitbucketTagsJson = await bitbucketTagsResponse.json() | ||
@@ -91,3 +91,3 @@ const newTags = bitbucketTagsJson.values | ||
})) | ||
.filter((tag) => !annotations.has(tag.name)); | ||
.filter((tag) => !annotations.has(tag.name)) | ||
@@ -109,6 +109,6 @@ for (let tag of newTags) { | ||
'POST' | ||
); | ||
) | ||
if (createAnnotationRes.status === 201) { | ||
posthog.capture('created_tag_annotation', { tag: tag.name }); | ||
posthog.capture('created_tag_annotation', { tag: tag.name }) | ||
} | ||
@@ -120,3 +120,3 @@ } | ||
try { | ||
const res = await fetch(url, { method: method, ...options }); | ||
const res = await fetch(url, { method: method, ...options }) | ||
return res | ||
@@ -127,7 +127,5 @@ } catch { | ||
} | ||
const res = await fetchWithRetry(url, options, (method = method), (isRetry = true)); | ||
const res = await fetchWithRetry(url, options, (method = method), (isRetry = true)) | ||
return res | ||
} | ||
} | ||
export { runEveryMinute, setupPlugin }; |
{ | ||
"name": "@posthog/bitbucket-release-tracker", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Track Bitbucket releases in PostHog.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
459746
9
174