def signin(): username = request.forms.get('username') password = request.forms.getunicode('password') if username is None or password is None: abort(400, "Request form doesn't contain username or password") if not is_username_valid(username) or not is_password_valid(password): abort(400, "Incorrect login or password") if not is_valid_pair(username, password): abort(400, "Incorrect login or password") sm.create_session(username) redirect('/')
def get_org_today(self, organization): if not utils.is_username_valid(organization): return "Invalid username" self.msg = "" self.msg += '{0} Today\'s updates for '.format('\U0001F5C4') \ + '[{0}](https://github.com/{0}):\n\n'.format(organization) commit_count = 0 repo_count = 0 today = datetime.now() yesterday = (today - timedelta(1)).strftime("%Y-%m-%dT%H:%M:%SZ") url = 'https://api.github.com/orgs/' + organization + '/repos' + self.url_parameters( ) req = loads(get(url).text) # Handles case where there's an API error try: if req['message'] is not None: logging.getLogger(__name__).error("API ERROR /today: " + req['message']) return "Unable to get updates for this organization at this time." except: pass repo_range = len( req) if len(req) <= 20 else 20 # Limita a 20 repositórios for i in range(repo_range): pushed_at = datetime.strptime(req[i]['pushed_at'], "%Y-%m-%dT%H:%M:%SZ") diff = datetime.now() - pushed_at if diff.days < 1: req2 = loads( get('https://api.github.com/repos/' + organization + '/' + req[i]['name'] + '/commits?since=' + yesterday).text) if len(req2) > 0: self.msg += '\n' + escape_to_markdown(str( req[i]['name'])) + ': ' + str(len(req2)) + ' commits' commit_count += len(req2) repo_count += 1 if commit_count > 0: self.msg = "*" + str(repo_count) + " repos updated with " + str( commit_count) + " commits!*\n" + self.msg else: self.msg = self.msg + "No repositories were updated today." return self.msg, commit_count
def get_org_repos(self, organization): if not utils.is_username_valid(organization): return "Invalid username" self.msg = "" self.msg += '{0} Repositories for '.format('\U0001F5C4') \ + '[{0}](https://github.com/{0}):\n\n'.format(organization) req = loads( get('https://api.github.com/orgs/' + organization + '/repos' + self.url_parameters()).text) for i in range(len(req)): # Name with URL self.msg += '\n\n[' + escape_to_markdown(str( req[i]['name'])) + '](' + str(req[i]['html_url']) + ')' # Description on the second line self.msg += '\n\U0001F4C4 ' + escape_to_markdown( str(req[i]['description'])) if len(req) == 0: self.msg += "No repositories found." return self.msg
def test_username_valid_with_hyphen_and_number(self): self.assertTrue(utils.is_username_valid("meunomee-julia99"))
def test_username_valid_only_char(self): self.assertTrue(utils.is_username_valid("meunomeejulia"))
def test_username_invalid_space(self): self.assertFalse(utils.is_username_valid("Issodai Talkey"))
def test_username_invalid_underscore(self): self.assertFalse(utils.is_username_valid("MeuNome_Julia99"))
def test_username_valid_upper_case(self): self.assertTrue(utils.is_username_valid("MeuNomeEJulia99"))