Last active
January 16, 2019 10:24
-
-
Save t-yamamoto-mercury-inc/62ad9dafab1c087b0b2686b1a941e2dd to your computer and use it in GitHub Desktop.
GoogleスプレッドシートからGithubにInssueを追加できるGoogleAppsScript https://qiita.com/ayasamind/items/38945bd69f8289d6ccaa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://qiita.com/ayasamind/items/38945bd69f8289d6ccaa を改造した | |
function newFunction() { | |
//シートから入力されたタイトル、ボディを取得する | |
SpreadsheetApp.getActiveSpreadsheet(); | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = spreadsheet.getActiveSheet(); | |
var lastRow = sheet.getLastRow(); | |
var issueCount = lastRow; | |
var title = ''; | |
var body = ''; | |
for (var i=2; i<=issueCount; i++){ | |
for (var j=1; j<4; j++){ | |
var range = sheet.getRange(i,j); | |
if (j==1){ | |
title = range.getValue(); | |
} else if (j==2){ | |
body = range.getValue(); | |
} else if (j==3){ | |
label = range.getValue(); | |
label = label.split(','); | |
} | |
} | |
var issue = {title:title,body:body,labels:label,}; | |
if (issue != ''){ | |
SpreadsheetApp.getActiveSpreadsheet(); | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = spreadsheet.getActiveSheet(); | |
var username = sheet.getRange(2,6).getValue(); | |
var repository = sheet.getRange(2,7).getValue(); | |
var accesstoken = sheet.getRange(2,8).getValue(); | |
var column_id = sheet.getRange(2,9).getValue(); // '1502844'; | |
var column_id2 = sheet.getRange(2,10).getValue(); // '3429320'; | |
var url = "https://api.github.com/repos/"+username+"/"+repository+"/issues?access_token="+accesstoken; | |
var options = | |
{ | |
"headers" : {"Accept": "application/vnd.github.inertia-preview+json"}, | |
"method" : "post", | |
"payload" : JSON.stringify(issue) | |
}; | |
var res = UrlFetchApp.fetch(url, options); | |
var resJson = JSON.parse(res.getContentText()); | |
var url2 = "https://api.github.com/projects/columns/"+column_id+"/cards?access_token="+accesstoken; | |
var issue2 = {"content_id": Number(""+resJson.id), "content_type": "Issue"}; | |
var options2 = | |
{ | |
"headers" : {"Accept": "application/vnd.github.inertia-preview+json"}, | |
"method" : "post", | |
"payload" : JSON.stringify(issue2) | |
}; | |
var res2 = UrlFetchApp.fetch(url2, options2); | |
if(column_id2 != ''){ | |
var url3 = "https://api.github.com/projects/columns/"+column_id2+"/cards?access_token="+accesstoken; | |
var issue3 = {"content_id": Number(""+resJson.id), "content_type": "Issue"}; | |
var options3 = | |
{ | |
"headers" : {"Accept": "application/vnd.github.inertia-preview+json"}, | |
"method" : "post", | |
"payload" : JSON.stringify(issue3) | |
}; | |
var res3 = UrlFetchApp.fetch(url3, options3); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment