2017-08-03 39 views
0

按照關於this的說明SO問題我能夠使用GitHub REST API和R包httrRCurl爲我擁有的組織創建回購。現在,我遇到了使用API​​刪除回購的問題。使用REST API刪除R中的Github組織回購

我在GitHub上創建了一個OAuth應用程序,並讓應用程序訪問我的組織。然後我運行下面的代碼來創建delete_repo作用域的標記。

library(httr) 
library(RCurl) 

# 1. Find OAuth settings for github: 
# http://developer.github.com/v3/oauth/ 
oauth_endpoints("github") 

# 2. Register an application at https://github.com/settings/applications 
# Insert your values below - if secret is omitted, it will look it up in 
# the GITHUB_CONSUMER_SECRET environmental variable. 
# 
# Use http://localhost:1410 as the callback url 
myapp <- oauth_app("TestApp", "app-number","secret-number") 
scope <- 'delete_repo' 
# 3. Get OAuth credentials 
github_token <- oauth2.0_token(oauth_endpoints("github"),scope=scope, myapp) 

每GitHub的API第3版開發人員指南,網址create組織中的一個新的回購協議是

https://api.github.com/orgs/:org/repos 

使用這個網址我能夠創建一個名爲我的組織的私人回購協議的可靠性「通過運行:

#Push repository to Github 
url_c = "https://api.github.com/orgs/Reliability/repos" 
data = list("name"= "newRepo", "private" = "true") 
POST(url = url_c, body = data, config(token = github_token)) 

delete回購,開發指南指出,URL應該是這樣的形式

DELETE repos/:owner/:repo 

對於一個組織的回購協議,我理解,這個URL應該是

https://api.github.com/orgs/:org/repos/:owner/:repo 

然而,當我運行下面的代碼,我得到沒有發現404的響應。

# Delete repository from Github organization 
url_d = "https://api.github.com/orgs/Reliability/repos/Auburngrads/newRepo" 
DELETE(url = url_d, config(token = github_token)) 

我錯過了什麼?

回答

1

GitHub開發人員指南中的措詞對於應該用於使用REST API刪除組織回購的URL有誤導作用。

開發人員指南指出,對delete回購,該URL應該是這樣的形式

DELETE repos/:owner/:repo 

然而,對於一個組織的回購協議,該URL的形式應爲

DELETE repos/:org/:repo 

我的能夠通過以下方式成功刪除組織中的「可靠性」回覆:1)確保我的應用令牌具有合適的delete_repo範圍,並且2)運行以下代碼

# Delete repository from Github organization 
url_d = "https://api.github.com/repos/Reliability/newRepo" 
DELETE(url = url_d, config(token = github_token)) 
相關問題