Skip to content

Commit

Permalink
feat: use dev api key from the repo secret
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol-Baranwal committed Feb 4, 2024
1 parent 267c5b9 commit 1415a01
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/save_articles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Run DevSync Action
uses: ./ # Path to the directory containing the action.yml
with:
gh-token: ${{ secrets.GITHUB_TOKEN }}
devApiKey: ${{ secrets.DEV_TOKEN }}
# gh-token: ${{ secrets.GITHUB_TOKEN }}
# devApiKey: ${{ secrets.DEV_TOKEN }}
outputDir: "/articles"
branch: "core_functionalities"
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ inputs:
devApiKey:
description: 'Dev API key (required)'
required: true
default: "${{ secrets.DEV_TOKEN }}"
gh-token:
description: 'The GitHub token for authentication.'
default: ${{ github.token }}
Expand Down
8 changes: 5 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ async function DevSync() {
core.setFailed("GitHub token is missing. Make sure to set the GITHUB_TOKEN secret.");
return;
}
const apiKey = core.getInput("devApiKey");
const outputDir = core.getInput("outputDir") || "/"; // Default is the root directory
const branch = core.getInput("branch");
const conventionalCommits = core.getInput("conventional_commits") === "true";
const articles = await (0, fetchDevToArticles_1.fetchDevToArticles)();
const articles = await (0, fetchDevToArticles_1.fetchDevToArticles)(apiKey);
(0, createMarkdownFile_1.createMarkdownFile)(articles, outputDir, branch, conventionalCommits);
core.notice("Articles fetched and saved successfully.");
}
Expand Down Expand Up @@ -145,10 +146,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fetchDevToArticles = void 0;
const node_fetch_1 = __importDefault(__nccwpck_require__(1793));
async function fetchDevToArticles() {
async function fetchDevToArticles(apiKey) {
const apiUrl = `https://dev.to/api/articles/me`;
const headers = {
"Content-Type": "application/json"
"Content-Type": "application/json",
"api-key": apiKey
};
const response = await (0, node_fetch_1.default)(apiUrl, { headers });
if (!response.ok) {
Expand Down
5 changes: 3 additions & 2 deletions dist/utils/fetchDevToArticles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchDevToArticles = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
async function fetchDevToArticles() {
async function fetchDevToArticles(apiKey) {
const apiUrl = `https://dev.to/api/articles/me`;
const headers = {
"Content-Type": "application/json"
"Content-Type": "application/json",
"api-key": apiKey
};
const response = await (0, node_fetch_1.default)(apiUrl, { headers });
if (!response.ok) {
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ async function DevSync() {
return
}

const apiKey = core.getInput("devApiKey")
const outputDir = core.getInput("outputDir") || "/" // Default is the root directory
const branch = core.getInput("branch")
const conventionalCommits = core.getInput("conventional_commits") === "true"

const articles = await fetchDevToArticles()
const articles = await fetchDevToArticles(apiKey)
createMarkdownFile(articles, outputDir, branch, conventionalCommits)
core.notice("Articles fetched and saved successfully.")
} catch (error) {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/fetchDevToArticles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { DevToArticle } from "../types"
import fetch from "node-fetch"

export async function fetchDevToArticles(): Promise<any[]> {
export async function fetchDevToArticles(
apiKey: string
): Promise<DevToArticle[]> {
const apiUrl = `https://dev.to/api/articles/me`

const headers: { [key: string]: string } = {
"Content-Type": "application/json"
"Content-Type": "application/json",
"api-key": apiKey
}

const response = await fetch(apiUrl, { headers })
Expand Down

0 comments on commit 1415a01

Please sign in to comment.