Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Commit

Permalink
add rm_tag_not_release.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
ickc committed Oct 8, 2018
1 parent 4977b86 commit e859d6a
Showing 1 changed file with 240 additions and 0 deletions.
240 changes: 240 additions & 0 deletions rm_tag_not_release.ipynb
@@ -0,0 +1,240 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bs4 import BeautifulSoup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import github3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from lxml import html"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import requests"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open(Path('/Users/kolen/gh_token'), 'r') as f:\n",
" token, userid = [line.strip() for line in f.readlines()]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gh = github3.login(token=token)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"repo = gh.repository('pandoc-extras', 'pandoc-nightly')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tag_names = {release.tag_name for release in repo.releases()}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"len(tag_names)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tag_names2 = {tag.name: tag for tag in repo.tags()}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"len(tag_names2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"assert tag_names.issubset(tag_names2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"surplus_tags = tag_names2.keys() - tag_names"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"len(surplus_tags)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"urls = np.array([\n",
" f'https://github.com/pandoc-extras/pandoc-nightly/releases/tag/{tag}'\n",
" for tag in surplus_tags\n",
"])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"result = np.array(\n",
" [\n",
" datetime.strptime(\n",
" BeautifulSoup(\n",
" requests.get(url).content,\n",
" \"html.parser\"\n",
" ).find_all('relative-time')[0].contents[0],\n",
" '%b %d, %Y'\n",
" )\n",
" for url in urls\n",
" ],\n",
" dtype=np.datetime64\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"surplus_tags_obj = [value for key, value in tag_names2.items() if key in surplus_tags]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"surplus_tags"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"for tag in surplus_tags:\n",
" !git tag -d {tag} && git push origin :{tag}"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "all3-intel",
"language": "python",
"name": "all3-intel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit e859d6a

Please sign in to comment.