From 1415a014be905c6be19d89a023b5aa7d53c3ea45 Mon Sep 17 00:00:00 2001 From: Anmol Baranwal Date: Sun, 4 Feb 2024 23:17:08 +0530 Subject: [PATCH] feat: use dev api key from the repo secret --- .github/workflows/save_articles.yml | 4 ++-- action.yml | 1 + dist/index.js | 8 +++++--- dist/utils/fetchDevToArticles.js | 5 +++-- src/index.ts | 3 ++- src/utils/fetchDevToArticles.ts | 7 +++++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.github/workflows/save_articles.yml b/.github/workflows/save_articles.yml index 8325c77..666f00b 100644 --- a/.github/workflows/save_articles.yml +++ b/.github/workflows/save_articles.yml @@ -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" diff --git a/action.yml b/action.yml index 8d6edec..623b1fc 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/dist/index.js b/dist/index.js index eba82f4..8074e29 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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."); } @@ -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) { diff --git a/dist/utils/fetchDevToArticles.js b/dist/utils/fetchDevToArticles.js index 4090988..cea86f9 100644 --- a/dist/utils/fetchDevToArticles.js +++ b/dist/utils/fetchDevToArticles.js @@ -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) { diff --git a/src/index.ts b/src/index.ts index 4415331..ec260b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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) { diff --git a/src/utils/fetchDevToArticles.ts b/src/utils/fetchDevToArticles.ts index 52ee1a9..80ea331 100644 --- a/src/utils/fetchDevToArticles.ts +++ b/src/utils/fetchDevToArticles.ts @@ -1,11 +1,14 @@ import { DevToArticle } from "../types" import fetch from "node-fetch" -export async function fetchDevToArticles(): Promise { +export async function fetchDevToArticles( + apiKey: string +): Promise { 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 })