Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use code to synchronize an issue in the github warehouse to the CSDN blog

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use code to synchronize an issue in the github warehouse to the CSDN blog". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use code to synchronize an issue in the github warehouse to the CSDN blog".

I am a lazy programmer. I wrote a lot of sharing articles in issue in the github repository and wanted to sync them to CSDN. But I don't want to copy and paste articles manually, so I want to automate it with code.

Example:

Https://github.com/i042416/KnowlegeRepository/issues/2215

This is one of my issue:

I use the following nodejs code to copy from the github repository issue to the CSDN blog:

Var config = require (". / mcConfig"); var request = require ('request'); var querystring = require (' querystring'); function createPost (oPost) {var url = "https://mp.csdn.net/mdeditor/saveArticle"; Var oBody = {title: oPost.title, markdowncontent: oPost.body, tags: "Fiori", categories: "Fiori", channel: "14", type: "original", articleedittype: "1", content: oPost.body}; var formData = querystring.stringify (oBody); var contentLength = formData.length Var createPostOptions = {url: url, method: "POST", headers: {"content-type": "application/x-www-form-urlencoded", "Content-Length": contentLength, "origin": "https://mp.csdn.net"," referer ":" https://mp.csdn.net/mdeditor", "User-Agent": "Mozilla/5.0 (Windows NT 10.0 Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36 "," cookie ": config.cookie}, body: formData}; return new Promise (function (resolve,reject) {var requestC = request.defaults ({jar: true}); console.log (" Step1: create post via url: "url) RequestC (createPostOptions,function (error,response,body) {if (error) {reject (error);} console.log ("response:" body); resolve (body);});} module.exports = createPost;var request = require ('request'); function getIssue (issueNumber) {var url = "https://api.github.com/repos/i042416/KnowlegeRepository/issues/" issueNumber Var getIssueOptions = {url: url, method: "GET", json:true, headers: {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"}} Return new Promise (function (resolve,reject) {var requestC = request.defaults ({jar: true}); console.log ("Step1: get issue detail via url:" url); requestC (getIssueOptions,function (error,response,body) {if (error) {console.log ("error occurred:" error); reject (error);} console.log ("title:" body.title) Console.log ("body:" body.body); for (var I = 0; I

< body.labels.length; i ){ console.log("label: " body.labels[i].name); } resolve(body); }); });}module.exports = getIssue;var readIssue = require("./readIssueMod");var createPost = require("./createPostMod");readIssue(2215).then(createPost).catch((error)=>

{console.log ("error:" error)})

Execution result:

Has been automatically synchronized to CSDN, convenient!

Thank you for reading, the above is the content of "how to use code to synchronize an issue in the github warehouse to the CSDN blog". After the study of this article, I believe you have a deeper understanding of how to synchronize an issue in the github warehouse to the CSDN blog with code, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report