Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Dec 5, 2020
1 parent ad32b57 commit 44e89d1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 19 deletions.
20 changes: 15 additions & 5 deletions 00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@
"We can get a sample `release` event payload as follows:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#exports\n",
"example_rel = example_payload(Event.release)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -232,8 +242,7 @@
}
],
"source": [
"example = example_payload(Event.release)\n",
"list(example), example.action"
"list(example_rel), example_rel.action"
]
},
{
Expand All @@ -260,7 +269,7 @@
}
],
"source": [
"', '.join(example.release)"
"', '.join(example_rel.release)"
]
},
{
Expand All @@ -278,10 +287,11 @@
"source": [
"#exports\n",
"def tweet_text(payload):\n",
" if 'workflow' in payload: payload = example_rel\n",
" def_tmpl = \"New #{repo} release: v{tag_name}. {html_url}\\n\\n{body}\"\n",
" tweet_tmpl = os.getenv('TWEETREL_TEMPLATE', def_tmpl)\n",
" rel = payload.release\n",
" owner,repo = example.repository.full_name.split('/')\n",
" owner,repo = payload.repository.full_name.split('/')\n",
" res = tweet_tmpl.format(repo=repo, tag_name=rel.tag_name, html_url=rel.html_url, body=rel.body)\n",
" if len(res)<=280: return res\n",
" return res[:279] + \"\""
Expand Down Expand Up @@ -310,7 +320,7 @@
}
],
"source": [
"print(tweet_text(example))"
"print(tweet_text(example_rel))"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<!-- do not remove -->


## 0.0.1
## 0.0.5

- Initial release

33 changes: 25 additions & 8 deletions docs/core.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,24 @@ <h2 id="Responding-to-the-release-event">Responding to the <code>release</code>

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">example</span> <span class="o">=</span> <span class="n">example_payload</span><span class="p">(</span><span class="n">Event</span><span class="o">.</span><span class="n">release</span><span class="p">)</span>
<span class="nb">list</span><span class="p">(</span><span class="n">example</span><span class="p">),</span> <span class="n">example</span><span class="o">.</span><span class="n">action</span>
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">example_rel</span> <span class="o">=</span> <span class="n">example_payload</span><span class="p">(</span><span class="n">Event</span><span class="o">.</span><span class="n">release</span><span class="p">)</span>
</pre></div>

</div>
</div>
</div>

</div>
{% endraw %}

{% raw %}

<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">list</span><span class="p">(</span><span class="n">example_rel</span><span class="p">),</span> <span class="n">example_rel</span><span class="o">.</span><span class="n">action</span>
</pre></div>

</div>
Expand Down Expand Up @@ -320,7 +336,7 @@ <h2 id="Responding-to-the-release-event">Responding to the <code>release</code>

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">example</span><span class="o">.</span><span class="n">release</span><span class="p">)</span>
<div class=" highlight hl-ipython3"><pre><span></span><span class="s1">&#39;, &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">example_rel</span><span class="o">.</span><span class="n">release</span><span class="p">)</span>
</pre></div>

</div>
Expand Down Expand Up @@ -364,7 +380,7 @@ <h2 id="Responding-to-the-release-event">Responding to the <code>release</code>


<div class="output_markdown rendered_html output_subarea ">
<h4 id="tweet_text" class="doc_header"><code>tweet_text</code><a href="https://github.com/fastai/tweetrel/tree/master/tweetrel/core.py#L35" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>tweet_text</code>(<strong><code>payload</code></strong>)</p>
<h4 id="tweet_text" class="doc_header"><code>tweet_text</code><a href="https://github.com/fastai/tweetrel/tree/master/tweetrel/core.py#L38" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>tweet_text</code>(<strong><code>payload</code></strong>)</p>
</blockquote>

</div>
Expand All @@ -385,10 +401,11 @@ <h4 id="tweet_text" class="doc_header"><code>tweet_text</code><a href="https://g
<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="k">def</span> <span class="nf">tweet_text</span><span class="p">(</span><span class="n">payload</span><span class="p">):</span>
<span class="k">if</span> <span class="s1">&#39;workflow&#39;</span> <span class="ow">in</span> <span class="n">payload</span><span class="p">:</span> <span class="n">payload</span> <span class="o">=</span> <span class="n">example_rel</span>
<span class="n">def_tmpl</span> <span class="o">=</span> <span class="s2">&quot;New #</span><span class="si">{repo}</span><span class="s2"> release: v</span><span class="si">{tag_name}</span><span class="s2">. </span><span class="si">{html_url}</span><span class="se">\n\n</span><span class="si">{body}</span><span class="s2">&quot;</span>
<span class="n">tweet_tmpl</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s1">&#39;TWEETREL_TEMPLATE&#39;</span><span class="p">,</span> <span class="n">def_tmpl</span><span class="p">)</span>
<span class="n">rel</span> <span class="o">=</span> <span class="n">payload</span><span class="o">.</span><span class="n">release</span>
<span class="n">owner</span><span class="p">,</span><span class="n">repo</span> <span class="o">=</span> <span class="n">example</span><span class="o">.</span><span class="n">repository</span><span class="o">.</span><span class="n">full_name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
<span class="n">owner</span><span class="p">,</span><span class="n">repo</span> <span class="o">=</span> <span class="n">payload</span><span class="o">.</span><span class="n">repository</span><span class="o">.</span><span class="n">full_name</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;/&#39;</span><span class="p">)</span>
<span class="n">res</span> <span class="o">=</span> <span class="n">tweet_tmpl</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">repo</span><span class="o">=</span><span class="n">repo</span><span class="p">,</span> <span class="n">tag_name</span><span class="o">=</span><span class="n">rel</span><span class="o">.</span><span class="n">tag_name</span><span class="p">,</span> <span class="n">html_url</span><span class="o">=</span><span class="n">rel</span><span class="o">.</span><span class="n">html_url</span><span class="p">,</span> <span class="n">body</span><span class="o">=</span><span class="n">rel</span><span class="o">.</span><span class="n">body</span><span class="p">)</span>
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">res</span><span class="p">)</span><span class="o">&lt;=</span><span class="mi">280</span><span class="p">:</span> <span class="k">return</span> <span class="n">res</span>
<span class="k">return</span> <span class="n">res</span><span class="p">[:</span><span class="mi">279</span><span class="p">]</span> <span class="o">+</span> <span class="s2">&quot;…&quot;</span>
Expand All @@ -415,7 +432,7 @@ <h4 id="tweet_text" class="doc_header"><code>tweet_text</code><a href="https://g

<div class="inner_cell">
<div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">tweet_text</span><span class="p">(</span><span class="n">example</span><span class="p">))</span>
<div class=" highlight hl-ipython3"><pre><span></span><span class="nb">print</span><span class="p">(</span><span class="n">tweet_text</span><span class="p">(</span><span class="n">example_rel</span><span class="p">))</span>
</pre></div>

</div>
Expand Down Expand Up @@ -460,7 +477,7 @@ <h4 id="tweet_text" class="doc_header"><code>tweet_text</code><a href="https://g


<div class="output_markdown rendered_html output_subarea ">
<h4 id="send_tweet" class="doc_header"><code>send_tweet</code><a href="https://github.com/fastai/tweetrel/tree/master/tweetrel/core.py#L45" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>send_tweet</code>()</p>
<h4 id="send_tweet" class="doc_header"><code>send_tweet</code><a href="https://github.com/fastai/tweetrel/tree/master/tweetrel/core.py#L49" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>send_tweet</code>()</p>
</blockquote>

</div>
Expand Down Expand Up @@ -584,7 +601,7 @@ <h2 id="Distributing-your-new-Action">Distributing your new Action<a class="anch


<div class="output_markdown rendered_html output_subarea ">
<h4 id="install" class="doc_header"><code>install</code><a href="https://github.com/fastai/tweetrel/tree/master/tweetrel/core.py#L51" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>install</code>()</p>
<h4 id="install" class="doc_header"><code>install</code><a href="https://github.com/fastai/tweetrel/tree/master/tweetrel/core.py#L55" class="source_link" style="float:right">[source]</a></h4><blockquote><p><code>install</code>()</p>
</blockquote>

</div>
Expand Down
2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author = Jeremy Howard
author_email = [email protected]
copyright = fastai
branch = master
version = 0.0.3
version = 0.0.5
min_python = 3.6
audience = Developers
language = English
Expand Down
2 changes: 1 addition & 1 deletion tweetrel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.0.3"
__version__ = "0.0.5"

from . import core
from .core import *
Expand Down
1 change: 1 addition & 0 deletions tweetrel/_nbdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

index = {"auth": "00_core.ipynb",
"twitter_api": "00_core.ipynb",
"example_rel": "00_core.ipynb",
"tweet_text": "00_core.ipynb",
"send_tweet": "00_core.ipynb",
"install": "00_core.ipynb"}
Expand Down
8 changes: 6 additions & 2 deletions tweetrel/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: 00_core.ipynb (unless otherwise specified).

__all__ = ['auth', 'twitter_api', 'tweet_text', 'send_tweet', 'install']
__all__ = ['auth', 'twitter_api', 'example_rel', 'tweet_text', 'send_tweet', 'install']

# Cell
from fastcore.utils import *
Expand Down Expand Up @@ -31,12 +31,16 @@ def twitter_api():
auth.set_access_token(access_token,access_token_secret)
return tweepy.API(auth)

# Cell
example_rel = example_payload(Event.release)

# Cell
def tweet_text(payload):
if 'workflow' in payload: payload = example_rel
def_tmpl = "New #{repo} release: v{tag_name}. {html_url}\n\n{body}"
tweet_tmpl = os.getenv('TWEETREL_TEMPLATE', def_tmpl)
rel = payload.release
owner,repo = example.repository.full_name.split('/')
owner,repo = payload.repository.full_name.split('/')
res = tweet_tmpl.format(repo=repo, tag_name=rel.tag_name, html_url=rel.html_url, body=rel.body)
if len(res)<=280: return res
return res[:279] + "…"
Expand Down

0 comments on commit 44e89d1

Please sign in to comment.