-
Notifications
You must be signed in to change notification settings - Fork 976
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'current' into wazi55/dbt-bq-doc-update
- Loading branch information
Showing
256 changed files
with
8,494 additions
and
3,781 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
blank_issues_enabled: true | ||
contact_links: | ||
- name: Want to see new content? Open a discussion! | ||
url: https://github.com/dbt-labs/docs.getdbt.com/discussions/new | ||
about: You can open a discussion to propose new content for the dbt product documentation. | ||
- name: Have questions about dbt? Join the Community! | ||
url: https://www.getdbt.com/community/join-the-community | ||
about: You can join the dbt Labs Community to ask and answer questions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
.github/ISSUE_TEMPLATE/zzz_add-adapter-to-trusted-list.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
name: Add adapter to Trusted list | ||
description: For adapter maintainers who wish to have theirs added to the list of Trusted adapters. | ||
title: "Trust dbt-myadapter" | ||
labels: ["adapter maintainers"] | ||
assignees: | ||
- dataders | ||
body: | ||
- type: markdown | ||
attributes: | ||
value: | | ||
We're excited that you'd like to support your adapter formally as "Trusted"! This template will ensure that you are aware of the process and the guidelines. Additionally, that you can vouch that your adapter currently meets the standards of a Trusted adapter. For more information, see [Trusted adapters](https://docs.getdbt.com/docs/trusted-adapters) | ||
- type: input | ||
id: adapter-repo | ||
attributes: | ||
label: Link to adapter repo | ||
description: Please link to the GitHub repo | ||
validations: | ||
required: true | ||
|
||
- type: input | ||
id: contact | ||
attributes: | ||
label: Contact Details | ||
description: How can we get in touch with you? | ||
placeholder: your preferred email and/or dbt Slack handle | ||
validations: | ||
required: true | ||
|
||
- type: dropdown | ||
id: author_type | ||
attributes: | ||
label: Which of these best describes you? | ||
options: | ||
- I am a dbt Community member | ||
- I work for the vendor on top of which the dbt adapter functions | ||
validations: | ||
required: true | ||
|
||
- type: checkboxes | ||
id: read-program-guide | ||
attributes: | ||
label: Please agree to the each of the following | ||
options: | ||
- label: I am a maintainer of the adapter being submited for Trusted status | ||
required: true | ||
- label: I have read both the [Trusted adapters](https://docs.getdbt.com/docs/trusted-adapters) and [Building a Trusted Adapter](https://docs.getdbt.com/guides/dbt-ecosystem/adapter-development/8-building-a-trusted-adapter) pages. | ||
required: true | ||
- label: I believe that the adapter currently meets the expectations given above | ||
required: true | ||
- label: I will ensure this adapter stays in compliance with the guidelines | ||
required: true | ||
- label: I understand that dbt Labs reserves the right to remove an adapter from the trusted adapter list at any time, should any of the below guidelines not be met | ||
required: true | ||
|
||
- type: textarea | ||
id: icon | ||
attributes: | ||
label: What icon should be used? | ||
description: | | ||
Please share an svg image that you'd like to be displayed in for your adapter. Normally, this is the logo for the data platform on top of which your adapter works. If there's a dark mode version, please also share that. | ||
Pasting the image from your clipboard will upload the file to GitHub and create markdown formatting for it to be rendered inline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# **what?** | ||
# Labels issues autogenerated in dbt-core | ||
|
||
# **why?** | ||
# To organize autogenerated issues from dbt-core to make it easier to find and track them. | ||
|
||
# **when?** | ||
# When an issue is opened by the FishtownBuildBot | ||
|
||
name: Add Labels to Autogenerated Issues | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
|
||
jobs: | ||
add_customized_labels: | ||
if: github.event.issue.user.login == 'FishtownBuildBot' | ||
permissions: | ||
issues: write | ||
|
||
runs-on: ubuntu-latest | ||
steps: | ||
- name: "Determine appropriate labels by repo in title" | ||
id: repo | ||
env: | ||
ISSUE_TITLE: ${{ github.event.issue.title }} | ||
run: | | ||
if [[ "$ISSUE_TITLE" == *"dbt-core"* ]]; then | ||
echo "labels='content,improvement,dbt Core'" >> $GITHUB_OUTPUT | ||
else | ||
echo "labels='content,improvement,adapters'" >> $GITHUB_OUTPUT | ||
fi | ||
- name: "Add Labels to autogenerated Issues" | ||
id: add-labels | ||
run: | | ||
gh issue edit ${{ github.event.issue.number }} --repo ${{ github.repository }} --add-label ${{ steps.repo.outputs.labels }} | ||
env: | ||
GH_TOKEN: ${{ secrets.DOCS_SECRET }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
const axios = require('axios') | ||
require("dotenv").config(); | ||
|
||
const { DISCOURSE_DEVBLOG_API_KEY , DISCOURSE_USER_SYSTEM } = process.env | ||
const DEVBLOG_PROD_URL = 'https://docs.getdbt.com/blog/' | ||
const DEV_ENV = 'dev-' | ||
const PREVIEW_ENV = 'deploy-preview-' | ||
|
||
// Set API endpoint and headers | ||
let discourse_endpoint = `https://discourse.getdbt.com` | ||
let headers = { | ||
'Accept': 'application/json', | ||
'Api-Key': DISCOURSE_DEVBLOG_API_KEY, | ||
'Api-Username': DISCOURSE_USER_SYSTEM, | ||
} | ||
|
||
async function getDiscourseComments(request, response) { | ||
let topicId, comments, DISCOURSE_TOPIC_ID; | ||
|
||
const blogUrl = await getBlogUrl(request) | ||
|
||
if (blogUrl === DEVBLOG_PROD_URL) { | ||
DISCOURSE_TOPIC_ID = 21 | ||
} else { | ||
DISCOURSE_TOPIC_ID = 2 | ||
} | ||
|
||
try { | ||
const env = | ||
blogUrl === DEVBLOG_PROD_URL | ||
? "" | ||
: blogUrl.includes("localhost") | ||
? DEV_ENV | ||
: PREVIEW_ENV; | ||
const postTitle = `${env}${request.query.title}`; | ||
const postSlug = request.query.slug; | ||
const cleanSlug = cleanUrl(request.query.slug); | ||
const externalId = truncateString(`${env}${cleanSlug}`); | ||
|
||
console.table({ | ||
blogUrl, | ||
postTitle, | ||
postSlug, | ||
cleanSlug, | ||
externalId, | ||
}); | ||
|
||
|
||
if (!postSlug) throw new Error("Unable to query Discourse API. Error reading slug."); | ||
|
||
topicId = await searchDiscourseExternalId(externalId); | ||
|
||
// First check if the dev blog post exists in Discourse | ||
// Get the comments if it does | ||
if (typeof topicId === "number") { | ||
comments = await getDiscourseTopicbyID(topicId); | ||
} else { | ||
// If the dev blog post does not exist in Discourse | ||
// Create a new topic and get the comments | ||
topicId = await createDiscourseTopic(postTitle, externalId, cleanSlug, blogUrl, DISCOURSE_TOPIC_ID); | ||
if (typeof topicId === "number") { | ||
comments = await getDiscourseTopicbyID(topicId); | ||
comments.shift(); | ||
comments = { topicId, comments }; | ||
|
||
return await response.status(200).json(comments); | ||
} else { | ||
console.log("Unable to create Discourse topic TopicID is not a number."); | ||
return await response.status(500).json({ error: "Unable to create Discourse topic TopicID is not a number." }); | ||
} | ||
} | ||
|
||
comments.shift(); | ||
comments = { topicId, comments }; | ||
|
||
return await response.status(200).json(comments); | ||
} catch (err) { | ||
console.log("err on getDiscourseComments", err); | ||
return await response.status(500).json({ error: "Unable to get topics from Discourse." }); | ||
} | ||
} | ||
|
||
async function createDiscourseTopic(title, externalId, slug, blogUrl, DISCOURSE_TOPIC_ID) { | ||
console.log(`Creating a new topic in Discourse - ${title}`) | ||
try { | ||
const response = await axios.post(`${discourse_endpoint}/posts`, { | ||
title: title, | ||
raw: `This is a companion discussion topic for the original entry at ${blogUrl}${slug}`, | ||
category: DISCOURSE_TOPIC_ID, | ||
embed_url: `${blogUrl}${slug}`, | ||
external_id: externalId, | ||
tags: ['devblog'], | ||
visible: false | ||
}, { headers }) | ||
|
||
let topicId = await response.data.topic_id | ||
|
||
console.log('Topic successfully created with topic_id', topicId) | ||
|
||
return topicId | ||
|
||
} catch(err) { | ||
console.log('err on createDiscourseTopic', err) | ||
return err | ||
} | ||
} | ||
|
||
async function getDiscourseTopicbyID(topicId) { | ||
console.log(`Topic found setting topic id - ${topicId}`) | ||
try { | ||
let response = await axios.get(`${discourse_endpoint}/t/${topicId}.json`, { headers }) | ||
let { data } = await response | ||
let post_stream = data.post_stream | ||
let post_count = data.posts_count | ||
|
||
// If there is more than one comment make the topic visibile in Discourse | ||
if (post_count > 1 && data.visible === false) { | ||
console.log(`Topic has more than one comment. Changing visibility to visible.`) | ||
await axios.put(`${discourse_endpoint}/t/${topicId}`, { | ||
visible: true | ||
}, { headers }) | ||
} | ||
|
||
// Filter only 'regular' posts in Discourse. (e.g. not moderator actions, small_actions, whispers) | ||
post_stream.posts = post_stream.posts.filter(post => post.post_type === 1) | ||
|
||
return post_stream.posts | ||
} catch(err) { | ||
console.log('err on getDiscourseTopicbyID', err) | ||
return err | ||
} | ||
} | ||
|
||
async function searchDiscourseExternalId(externalId) { | ||
console.log(`Searching for external_id in Discourse - ${externalId}`); | ||
try { | ||
const data = await axios.get(`${discourse_endpoint}/t/external_id/${externalId}.json`, { headers }); | ||
return data.data.id; | ||
} catch (err) { | ||
if (err.response.status === 404) { | ||
console.log("No topics found in Discourse."); | ||
return null; | ||
} | ||
console.log("Unable to search Discourse for external_id.", err); | ||
return err; | ||
} | ||
} | ||
|
||
|
||
// Truncate external_id to 50 characters per Discourse API requirements | ||
function truncateString(str) { | ||
if (str.length <= 50) { | ||
return str | ||
} | ||
return str.slice(0, 50) | ||
} | ||
|
||
// Remove query params and hash from URL to prevent duplicate topics | ||
function cleanUrl(url) { | ||
return url.split("?")[0].split("#")[0]; | ||
} | ||
|
||
// Create a function to get the host name from the request and add /blog/ to the end | ||
async function getBlogUrl(req) { | ||
const host = req.headers.host | ||
return `https://${host}/blog/` | ||
} | ||
|
||
module.exports = getDiscourseComments; |
Oops, something went wrong.