trying to fix ci release upload

removed future date checking
This commit is contained in:
Mariotaku Lee 2015-09-21 18:15:42 +08:00
parent 0bff453c4b
commit ebf8b64851
5 changed files with 72 additions and 56 deletions

View File

@ -34,6 +34,12 @@ addons:
apt:
packages:
- python2.7
- libmagic1
before_script:
- export PATH=$HOME/.local/bin:$PATH
- pip install -r ./scripts/requirements.txt --user
script: ./gradlew build --no-daemon

2
scripts/requirements.txt Normal file
View File

@ -0,0 +1,2 @@
uritemplate
python-magic

View File

@ -4,15 +4,16 @@ from __future__ import print_function
import os
import sys
import httplib
import urllib
import urlparse
import urllib2
import json
import fnmatch
import re
import magic
import uritemplate
import string
from os import getenv
from subprocess import check_output
from subprocess import CalledProcessError
from urllib2 import HTTPError
__author__ = 'mariotaku'
git_https_url_prefix = 'https://github.com/'
@ -46,6 +47,9 @@ if not user_repo_name:
if user_repo_name.endswith(git_file_suffix):
user_repo_name = user_repo_name[:-len(git_file_suffix)]
github_user_name = string.split(user_repo_name, '/')[0]
github_repo_name = string.split(user_repo_name, '/')[1]
current_tag = None
current_tag_body = None
try:
@ -68,13 +72,27 @@ if not github_access_token:
github_authorization_header = "token %s" % github_access_token
print('Creating release for tag %s' % current_tag)
req_headers = {'Accept': github_header_accept}
conn = httplib.HTTPSConnection('api.github.com')
conn.request('POST', '/repos/%s/releases' % user_repo_name,
body=json.dumps({
request = urllib2.Request(
uritemplate.expand('https://api.github.com/repos/{user}/{repo}/releases/tags/{tag}',
{'user': github_user_name, 'repo': github_repo_name, 'tag': current_tag}),
headers={
'Accept': github_header_accept,
'Authorization': github_authorization_header,
'User-Agent': github_header_user_agent
})
response = None
try:
response = urllib2.urlopen(request)
except HTTPError, err:
print(err.code)
if err.code == 404:
print('Creating release for tag %s' % current_tag)
request = urllib2.Request(
uritemplate.expand('https://api.github.com/repos/{user}/{repo}/releases',
{'user': github_user_name, 'repo': github_repo_name}),
data=json.dumps({
'tag_name': current_tag,
'name': "Version %s" % current_tag,
'body': current_tag_body
@ -85,37 +103,36 @@ conn.request('POST', '/repos/%s/releases' % user_repo_name,
'Content-Type': 'application/json',
'User-Agent': github_header_user_agent
})
response = conn.getresponse()
if response.status == 422:
conn = httplib.HTTPSConnection('api.github.com')
conn.request('GET', '/repos/%s/releases/tags/%s' % (user_repo_name, current_tag),
headers={
'Accept': github_header_accept,
'Authorization': github_authorization_header,
'User-Agent': github_header_user_agent
})
response = conn.getresponse()
try:
response = urllib2.urlopen(request)
except HTTPError:
print('Unable to create release, abort', file=sys.stderr)
exit(0)
else:
response = None
if response.status not in range(200, 204):
print('Unable to create or get release, abort', file=sys.stderr)
if not response:
print('Unable to get release, abort', file=sys.stderr)
exit(0)
response_values = json.loads(response.read())
upload_url = urlparse.urlparse(re.sub('\{\?([\w\d_\-]+)\}', '', response_values['upload_url']))
for root, dirnames, filenames in os.walk(os.getcwd()):
for filename in fnmatch.filter(filenames, '*-release.apk'):
conn = httplib.HTTPSConnection(upload_url.hostname)
conn.request('POST', "%s?%s" % (upload_url.path, urllib.urlencode({'name': filename})),
body=open(os.path.join(root, filename), 'r'),
file_path = os.path.join(root, filename)
request = urllib2.Request(
uritemplate.expand(response_values['upload_url'], {'name': filename}),
data=open(file_path, 'rb'),
headers={
'Accept': github_header_accept,
'Authorization': github_authorization_header,
'Content-Type': 'application/json',
'Content-Type': magic.from_file(file_path, mime=True),
'Content-Length': os.path.getsize(file_path),
'User-Agent': github_header_user_agent
})
response = conn.getresponse()
if response.status in range(200, 204):
print("Upload %s success" % filename)
else:
print("Upload %s returned %d" % (filename, response.status), file=sys.stderr)
print("Uploading %s ..." % filename),
try:
response = urllib2.urlopen(request)
print("OK")
except HTTPError, err:
print("Error %d" % err.code)

View File

@ -70,7 +70,6 @@ public class TwitterDateConverter extends StringBasedTypeConverter<Date> {
if (date != null) return date;
try {
date = mDateFormat.parse(string);
checkTime(string, date);
} catch (ParseException e) {
AbsLogger.error("Unrecognized date: " + string, e);
return null;
@ -78,14 +77,6 @@ public class TwitterDateConverter extends StringBasedTypeConverter<Date> {
return date;
}
private void checkTime(String string, Date date) {
final long currentTime = System.currentTimeMillis();
if (date.getTime() - currentTime > ONE_MINUTE) {
AbsLogger.error("Tweet date from future, raw string: " + string + ", date parsed: "
+ date + ", current time is " + currentTime);
}
}
private Date parseTwitterDate(String string) {
final String[] segs = StringUtils.split(string, ' ');
if (segs.length != 6) {
@ -114,7 +105,6 @@ public class TwitterDateConverter extends StringBasedTypeConverter<Date> {
AbsLogger.error("Week mismatch " + string + " => " + date);
return null;
}
checkTime(string, date);
return date;
}

View File

@ -1376,6 +1376,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
public int getItemViewType(int position) {
final int conversationCount = getConversationCount();
if (position == getItemCount() - 1) {
// Space is always the last item
return VIEW_TYPE_SPACE;
} else if (position < conversationCount) {
return mConversation != null ? VIEW_TYPE_LIST_STATUS : VIEW_TYPE_CONVERSATION_LOAD_INDICATOR;