這篇文章主要講解了“怎么用代碼將github倉庫里某個issue同步到CSDN博客上”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“怎么用代碼將github倉庫里某個issue同步到CSDN博客上”吧!
10年積累的網(wǎng)站設(shè)計制作、成都做網(wǎng)站經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有鳳凰免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
我是一個懶惰的程序員。我在github倉庫里用issue的方式寫了很多分享文章,想同步到CSDN上。但是我又不想一篇篇手動復(fù)制粘貼,因此想用代碼來實現(xiàn)自動化。
例子:
https://github.com/i042416/KnowlegeRepository/issues/2215
這是我的一個issue:
我使用下面這些nodejs代碼實現(xiàn)從github 倉庫issue到CSDN博客的拷貝:
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)});
執(zhí)行結(jié)果:
已經(jīng)自動同步到CSDN了,方便!
感謝各位的閱讀,以上就是“怎么用代碼將github倉庫里某個issue同步到CSDN博客上”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對怎么用代碼將github倉庫里某個issue同步到CSDN博客上這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!