Skip to content

Commit

Permalink
Merge branch 'current' into wazi55/dbt-bq-doc-update
Browse files Browse the repository at this point in the history
  • Loading branch information
wazi55 authored Sep 28, 2023
2 parents b5c307f + bc4f0a7 commit 13051fc
Show file tree
Hide file tree
Showing 256 changed files with 8,494 additions and 3,781 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ body:
label: Additional information
description: Add any other context or screenshots about the feature request here.
validations:
required: false
required: false
3 changes: 0 additions & 3 deletions .github/ISSUE_TEMPLATE/config.yml
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.
8 changes: 4 additions & 4 deletions .github/ISSUE_TEMPLATE/improve-the-site.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Improve the docs.getdbt.com site
description: Make a suggestion or report a problem about the technical implementation of docs.getdbt.com.
labels: ["engineering"]
name: Report a docs.getdbt.com site issue
description: Report a problem about the technical implementation of docs.getdbt.com.
labels: ["engineering","bug"]
body:
- type: markdown
attributes:
Expand Down Expand Up @@ -39,4 +39,4 @@ body:
label: Additional information
description: Any additional information, configuration, or data that might be necessary to reproduce the issue.
validations:
required: false
required: false
33 changes: 0 additions & 33 deletions .github/ISSUE_TEMPLATE/new-dbt-feature.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/ISSUE_TEMPLATE/zzz_add-adapter-to-trusted-list.yml
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
40 changes: 40 additions & 0 deletions .github/workflows/autogenerated_labeler.yml
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 }}
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ website/yarn.lock
website/node_modules
website/i18n/*

# Local vs code
# IDE configs
.vscode
.idea

# Local Netlify folder
.netlify

.vscode
.eslintcache

# Local Vercel folder
.vercel
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ You can add code snippets and other content in a tabbed view. To learn more abou

# Running the Docs site locally

You can click a link available in a netlify bot PR comment to see and review your changes rendered on a staging server. You are also able to see and review your proposed modifications locally on your computer. Our setup instructions use [homebrew](https://brew.sh/):
You can click a link available in a Vercel bot PR comment to see and review your changes rendered on a staging server. You are also able to see and review your proposed modifications locally on your computer. Our setup instructions use [homebrew](https://brew.sh/):

## Prerequisites

Expand Down
2 changes: 1 addition & 1 deletion contributing/single-sourcing-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ This component can be added directly to a markdown file in a similar way as othe
Both properties can be used together to set a range where the content should show. In the example below, this content will only show if the selected version is between **0.21** and **1.0**:

```markdown
<VersionBlock lastVersion="1.0">
<VersionBlock lastVersion="1.6">

Versioned content here

Expand Down
5 changes: 4 additions & 1 deletion website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ yarn-error.log*
# feeds
/static/feeds/atom.xml
/static/feeds/rss.json
/static/feeds/rss.xml
/static/feeds/rss.xml

# Local Vercel folder
.vercel
169 changes: 169 additions & 0 deletions website/api/get-discourse-comments.js
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;
Loading

0 comments on commit 13051fc

Please sign in to comment.