怎么用代码将github仓库里某个issue同步到CSDN博客上-创新互联
这篇文章主要讲解了“怎么用代码将github仓库里某个issue同步到CSDN博客上”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用代码将github仓库里某个issue同步到CSDN博客上”吧!
创新互联,为您提供网站建设、重庆网站制作、网站营销推广、网站开发设计,对服务成都电动窗帘等多个行业拥有丰富的网站建设及推广经验。创新互联网站建设公司成立于2013年,提供专业网站制作报价服务,我们深知市场的竞争激烈,认真对待每位客户,为客户提供赏心悦目的作品。 与客户共同发展进步,是我们永远的责任!我是一个懒惰的程序员。我在github仓库里用issue的方式写了很多分享文章,想同步到CSDN上。但是我又不想一篇篇手动复制粘贴,因此想用代码来实现自动化。
例子:
https://github.com/i042416/KnowlegeRepository/issues/2215
这是我的一个issue:
我使用下面这些nodejs代码实现从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)});
执行结果:
已经自动同步到CSDN了,方便!
感谢各位的阅读,以上就是“怎么用代码将github仓库里某个issue同步到CSDN博客上”的内容了,经过本文的学习后,相信大家对怎么用代码将github仓库里某个issue同步到CSDN博客上这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
本文题目:怎么用代码将github仓库里某个issue同步到CSDN博客上-创新互联
网站网址:http://azwzsj.com/article/dgesdj.html