#Github # Update API using API or delete only a specific label # python script example

<ul>
<li> Specification to receive editing information on json standard input (array of objects) </li>
<li> The action to delete a specific label is to obtain existing issue information, process the array of labels in a python script, and pass it to the edit API. </li>
</ul>

<h1> python </h1>

<pre> <code class="py">#!/usr/bin/env python3 
 # -*- coding: utf-8 -*- 
 
 import os, json, re, requests, sys, funcy 
 
 USER_NAME = os.environ.get(&#39;USER_NAME&#39;) 
 API_KEY = os.environ.get(&#39;API_KEY&#39;) 
 
 edits = json.loads(sys.stdin.read()) 
 
 session = requests.Session() 
 session.auth = (USER_NAME, API_KEY) 
 
 print(edits) 
 
 def get_issue(issue): 
 issue_api_url = &#39;https://api.github.com/repos/&#39; + issue[&#39;owner&#39;] + &#39;/&#39; + issue[&#39;repository&#39;] + &#39;/issues/&#39; + str(issue[&#39;number&#39;]) 
 res = requests.get(issue_api_url) 
 return(res.json()) 
 
 results = [] 
 
 for edit in edits: 
 issue_number = str(edit[&#39;number&#39;]) 
 owner = edit[&#39;owner&#39;] 
 repository = edit[&#39;repository&#39;] 
 
 edit_api_url = &#39;https://api.github.com/repos/%s/%s/issues/%s&#39; % (owner, repository, issue_number) 
 
 update = {} 
 
 if &#39;title&#39; in edit: 
 update[&#39;title&#39;] = edit[&#39;title&#39;] 
 
 if &#39;body&#39; in edit: 
 update[&#39;body&#39;] = edit[&#39;body&#39;] 
 
 if &#39;labels&#39; in edit: 
 update[&#39;labels&#39;] = edit[&#39;labels&#39;] 
 
 if &#39;remove_labels&#39; in edit: 
 issue = get_issue(edit) 
 label_names = list(funcy.pluck(&#39;name&#39;, issue[&#39;labels&#39;])) 
 
 update[&#39;labels&#39;] = list(set(label_names) - set(edit[&#39;remove_labels&#39;])) 
 
 res = session.post(edit_api_url, json.dumps(update)) 
 
 results.append(res.json()) 
 
 print(json.dumps(results)) 
 
 
</code> </pre>

<h1> Specify and edit labels </h1>

<pre> <code>$ echo &#39;[{ &quot;number&quot;: 97, &quot;owner&quot;: &quot;YumaInaura&quot;, &quot;repository&quot;: &quot;playground&quot;, &quot;labels&quot;: [&quot;label1&quot;,&quot;label2&quot;,&quot;label3&quot;] }]&#39; | USER_NAME=YumaInaura API_KEY=$(cat ~/.secret/github-api-key) ./edit-issue.py 
 
 [{&#39;number&#39;: 97, &#39;owner&#39;: &#39;YumaInaura&#39;, &#39;repository&#39;: &#39;playground&#39;, &#39;labels&#39;: [&#39;label1&#39;, &#39;label2&#39;, &#39;label3&#39;]}] 
 [{&quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97&quot;, &quot;repository_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground&quot;, &quot;labels_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/labels{/name}&quot;, &quot;comments_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/comments&quot;, &quot;events_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/events&quot;, &quot;html_url&quot;: &quot;https://github.com/YumaInaura/playground/issues/97&quot;, &quot;id&quot;: 432358471, &quot;node_id&quot;: &quot;MDU6SXNzdWU0MzIzNTg0NzE=&quot;, &quot;number&quot;: 97, &quot;title&quot;: &quot;x&quot;, &quot;user&quot;: {&quot;login&quot;: &quot;YumaInaura&quot;, &quot;id&quot;: 13635059, &quot;node_id&quot;: &quot;MDQ6VXNlcjEzNjM1MDU5&quot;, &quot;avatar_url&quot;: &quot;https://avatars2.githubusercontent.com/u/13635059?v=4&quot;, &quot;gravatar_id&quot;: &quot;&quot;, &quot;url&quot;: &quot;https://api.github.com/users/YumaInaura&quot;, &quot;html_url&quot;: &quot;https://github.com/YumaInaura&quot;, &quot;followers_url&quot;: &quot;https://api.github.com/users/YumaInaura/followers&quot;, &quot;following_url&quot;: &quot;https://api.github.com/users/YumaInaura/following{/other_user}&quot;, &quot;gists_url&quot;: &quot;https://api.github.com/users/YumaInaura/gists{/gist_id}&quot;, &quot;starred_url&quot;: &quot;https://api.github.com/users/YumaInaura/starred{/owner}{/repo}&quot;, &quot;subscriptions_url&quot;: &quot;https://api.github.com/users/YumaInaura/subscriptions&quot;, &quot;organizations_url&quot;: &quot;https://api.github.com/users/YumaInaura/orgs&quot;, &quot;repos_url&quot;: &quot;https://api.github.com/users/YumaInaura/repos&quot;, &quot;events_url&quot;: &quot;https://api.github.com/users/YumaInaura/events{/privacy}&quot;, &quot;received_events_url&quot;: &quot;https://api.github.com/users/YumaInaura/received_events&quot;, &quot;type&quot;: &quot;User&quot;, &quot;site_admin&quot;: false}, &quot;labels&quot;: [{&quot;id&quot;: 1315925096, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk2&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label1&quot;, &quot;name&quot;: &quot;label1&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}, {&quot;id&quot;: 1315925097, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk3&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label2&quot;, &quot;name&quot;: &quot;label2&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}, {&quot;id&quot;: 1315925098, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk4&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label3&quot;, &quot;name&quot;: &quot;label3&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}], &quot;state&quot;: &quot;open&quot;, &quot;locked&quot;: false, &quot;assignee&quot;: null, &quot;assignees&quot;: [], &quot;milestone&quot;: null, &quot;comments&quot;: 0, &quot;created_at&quot;: &quot;2019-04-12T02:25:03Z&quot;, &quot;updated_at&quot;: &quot;2019-04-12T08:38:30Z&quot;, &quot;closed_at&quot;: null, &quot;author_association&quot;: &quot;OWNER&quot;, &quot;body&quot;: &quot;ohg\nwhatyes&quot;, &quot;closed_by&quot;: null}] 
</code> </pre>

<h1> Delete a specific label </h1>

<pre> <code>$ echo &#39;[{ &quot;number&quot;: 97, &quot;owner&quot;: &quot;YumaInaura&quot;, &quot;repository&quot;: &quot;playground&quot;, &quot;remove_labels&quot;: [&quot;label2&quot;] }]&#39; | USER_NAME=YumaInaura API_KEY=$(cat ~/.secret/github-api-key) ./edit-issue.py 
 
 [{&#39;number&#39;: 97, &#39;owner&#39;: &#39;YumaInaura&#39;, &#39;repository&#39;: &#39;playground&#39;, &#39;remove_labels&#39;: [&#39;label2&#39;]}] 
 [{&quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97&quot;, &quot;repository_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground&quot;, &quot;labels_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/labels{/name}&quot;, &quot;comments_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/comments&quot;, &quot;events_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/events&quot;, &quot;html_url&quot;: &quot;https://github.com/YumaInaura/playground/issues/97&quot;, &quot;id&quot;: 432358471, &quot;node_id&quot;: &quot;MDU6SXNzdWU0MzIzNTg0NzE=&quot;, &quot;number&quot;: 97, &quot;title&quot;: &quot;x&quot;, &quot;user&quot;: {&quot;login&quot;: &quot;YumaInaura&quot;, &quot;id&quot;: 13635059, &quot;node_id&quot;: &quot;MDQ6VXNlcjEzNjM1MDU5&quot;, &quot;avatar_url&quot;: &quot;https://avatars2.githubusercontent.com/u/13635059?v=4&quot;, &quot;gravatar_id&quot;: &quot;&quot;, &quot;url&quot;: &quot;https://api.github.com/users/YumaInaura&quot;, &quot;html_url&quot;: &quot;https://github.com/YumaInaura&quot;, &quot;followers_url&quot;: &quot;https://api.github.com/users/YumaInaura/followers&quot;, &quot;following_url&quot;: &quot;https://api.github.com/users/YumaInaura/following{/other_user}&quot;, &quot;gists_url&quot;: &quot;https://api.github.com/users/YumaInaura/gists{/gist_id}&quot;, &quot;starred_url&quot;: &quot;https://api.github.com/users/YumaInaura/starred{/owner}{/repo}&quot;, &quot;subscriptions_url&quot;: &quot;https://api.github.com/users/YumaInaura/subscriptions&quot;, &quot;organizations_url&quot;: &quot;https://api.github.com/users/YumaInaura/orgs&quot;, &quot;repos_url&quot;: &quot;https://api.github.com/users/YumaInaura/repos&quot;, &quot;events_url&quot;: &quot;https://api.github.com/users/YumaInaura/events{/privacy}&quot;, &quot;received_events_url&quot;: &quot;https://api.github.com/users/YumaInaura/received_events&quot;, &quot;type&quot;: &quot;User&quot;, &quot;site_admin&quot;: false}, &quot;labels&quot;: [{&quot;id&quot;: 1315925096, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk2&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label1&quot;, &quot;name&quot;: &quot;label1&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}, {&quot;id&quot;: 1315925098, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk4&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label3&quot;, &quot;name&quot;: &quot;label3&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}], &quot;state&quot;: &quot;open&quot;, &quot;locked&quot;: false, &quot;assignee&quot;: null, &quot;assignees&quot;: [], &quot;milestone&quot;: null, &quot;comments&quot;: 0, &quot;created_at&quot;: &quot;2019-04-12T02:25:03Z&quot;, &quot;updated_at&quot;: &quot;2019-04-12T08:38:37Z&quot;, &quot;closed_at&quot;: null, &quot;author_association&quot;: &quot;OWNER&quot;, &quot;body&quot;: &quot;ohg\nwhatyes&quot;, &quot;closed_by&quot;: null}] 
 
</code> </pre>

<h1> Edit the title </h1>

<pre> <code>$ echo &#39;[{ &quot;number&quot;: 97, &quot;owner&quot;: &quot;YumaInaura&quot;, &quot;repository&quot;: &quot;playground&quot;, &quot;title&quot; : &quot;AS&quot; }]&#39; | USER_NAME=YumaInaura API_KEY=$(cat ~/.secret/github-api-key) ./edit-issue.py 
 [{&#39;number&#39;: 97, &#39;owner&#39;: &#39;YumaInaura&#39;, &#39;repository&#39;: &#39;playground&#39;, &#39;title&#39;: &#39;AS&#39;}] 
 [{&quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97&quot;, &quot;repository_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground&quot;, &quot;labels_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/labels{/name}&quot;, &quot;comments_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/comments&quot;, &quot;events_url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/issues/97/events&quot;, &quot;html_url&quot;: &quot;https://github.com/YumaInaura/playground/issues/97&quot;, &quot;id&quot;: 432358471, &quot;node_id&quot;: &quot;MDU6SXNzdWU0MzIzNTg0NzE=&quot;, &quot;number&quot;: 97, &quot;title&quot;: &quot;AS&quot;, &quot;user&quot;: {&quot;login&quot;: &quot;YumaInaura&quot;, &quot;id&quot;: 13635059, &quot;node_id&quot;: &quot;MDQ6VXNlcjEzNjM1MDU5&quot;, &quot;avatar_url&quot;: &quot;https://avatars2.githubusercontent.com/u/13635059?v=4&quot;, &quot;gravatar_id&quot;: &quot;&quot;, &quot;url&quot;: &quot;https://api.github.com/users/YumaInaura&quot;, &quot;html_url&quot;: &quot;https://github.com/YumaInaura&quot;, &quot;followers_url&quot;: &quot;https://api.github.com/users/YumaInaura/followers&quot;, &quot;following_url&quot;: &quot;https://api.github.com/users/YumaInaura/following{/other_user}&quot;, &quot;gists_url&quot;: &quot;https://api.github.com/users/YumaInaura/gists{/gist_id}&quot;, &quot;starred_url&quot;: &quot;https://api.github.com/users/YumaInaura/starred{/owner}{/repo}&quot;, &quot;subscriptions_url&quot;: &quot;https://api.github.com/users/YumaInaura/subscriptions&quot;, &quot;organizations_url&quot;: &quot;https://api.github.com/users/YumaInaura/orgs&quot;, &quot;repos_url&quot;: &quot;https://api.github.com/users/YumaInaura/repos&quot;, &quot;events_url&quot;: &quot;https://api.github.com/users/YumaInaura/events{/privacy}&quot;, &quot;received_events_url&quot;: &quot;https://api.github.com/users/YumaInaura/received_events&quot;, &quot;type&quot;: &quot;User&quot;, &quot;site_admin&quot;: false}, &quot;labels&quot;: [{&quot;id&quot;: 1315925096, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk2&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label1&quot;, &quot;name&quot;: &quot;label1&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}, {&quot;id&quot;: 1315925098, &quot;node_id&quot;: &quot;MDU6TGFiZWwxMzE1OTI1MDk4&quot;, &quot;url&quot;: &quot;https://api.github.com/repos/YumaInaura/playground/labels/label3&quot;, &quot;name&quot;: &quot;label3&quot;, &quot;color&quot;: &quot;ededed&quot;, &quot;default&quot;: false}], &quot;state&quot;: &quot;open&quot;, &quot;locked&quot;: false, &quot;assignee&quot;: null, &quot;assignees&quot;: [], &quot;milestone&quot;: null, &quot;comments&quot;: 0, &quot;created_at&quot;: &quot;2019-04-12T02:25:03Z&quot;, &quot;updated_at&quot;: &quot;2019-04-12T08:43:41Z&quot;, &quot;closed_at&quot;: null, &quot;author_association&quot;: &quot;OWNER&quot;, &quot;body&quot;: &quot;ohg\nwhatyes&quot;, &quot;closed_by&quot;: null}] 
</code> </pre>


# Original by Github issue

https://github.com/YumaInaura/YumaInaura/issues/1221








<!-- Update From Qiita API -->

# チャットメンバー募集


何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

https://line.me/ti/g2/eEPltQ6Tzh3pYAZV8JXKZqc7PJ6L0rpm573dcQ





# Twitter


https://twitter.com/YumaInaura


<!-- Update From Qiita API -->