Esempio n. 1
0
    def calculate_range(
        self,
        repository_branch: str,
    ) -> str:
        repo = self.git_helper.repo
        branch_head = self.git_helper.fetch_head(ref=repository_branch)
        if not branch_head:
            fail(
                f'could not determine branch head of {repository_branch} branch'
            )
        range_start = _.head(
            self.reachable_release_tags_from_commit(
                repo=repo,
                commit=branch_head,
            ), )

        try:
            # better readable range_end by describing head commit
            range_end = repo.git.describe(branch_head, tags=True)
        except GitError as err:
            logger.warning(
                'failed to describe branch head, maybe the repository has no tags? '
                f'GitError: {err}. Falling back to branch head commit hash.')
            range_end = branch_head.hexsha

        commit_range = f'{range_start}..{range_end}'
        return commit_range
Esempio n. 2
0
def calculate_range(
    repository_branch: str,
    git_helper: GitHelper,
    github_helper: GitHubRepositoryHelper,
) -> str:
    repo = git_helper.repo
    branch_head = git_helper.fetch_head(ref=repository_branch)
    if not branch_head:
        fail('could not determine branch head of {branch} branch'.format(
            branch=repository_branch))
    range_start = _.head(
        reachable_release_tags_from_commit(github_helper, repo, branch_head))

    try:
        # better readable range_end by describing head commit
        range_end = repo.git.describe(branch_head)
    except GitError as err:
        warning(
            'failed to describe branch head, maybe the repository has no tags? '
            'GitError: {err}. Falling back to branch head commit hash.'.format(
                err=err))
        range_end = branch_head.hexsha

    commit_range = "{start}..{end}".format(start=range_start, end=range_end)
    return commit_range
Esempio n. 3
0
    def __init__(self, filename):
        """Init method."""
        super(APKParse, self).__init__()
        self.filename = filename
        self.valid_zip = False

        parse_data = self.get_aapt_parse_data('package')
        self.parse_dict = dict(
            item.split('=') for item in _.head(parse_data).split(' '))
Esempio n. 4
0
 def parse_package_version(self):
     """Parse package and version from apk."""
     parse_data = self.get_aapt_parse_data('package')
     package, version = '', ''
     if not parse_data:
         return package, version
     parse_dict = dict(
         item.split('=') for item in _.head(parse_data).split(' '))
     package = parse_dict.get('name', '')
     version = parse_dict.get('versionName', '')
     return package, version
Esempio n. 5
0
query = "*"
if args.since:
    query = "date%%3A>now-%s" % args.since
if args.query:
    query = "%s AND (%s)" % (query, args.query)

if args.action == "showbrands":
    r = session.get("https://pro.urlscan.com/api/v1/pro/kits")
    if not r.status_code == requests.codes.ok:
        logging.error("Error fetching brand definitions: %s" % r.json())
        sys.exit(1)
    for kit in r.json()["kits"]:
        print("="*80)
        print("%s - %s (%s)\nKey: %s\nWhitelisted domains: %s" % (
            kit["name"],
            _.head(_.get(kit, "vertical", [])),
            _.head(_.get(kit, "country", [])),
            kit["key"],
            _.get(kit, "terms.domains", [])
        ))
        print("URL: https://pro.urlscan.com/search?filter=%%24phishing_%s" % kit["key"])
        print("API: https://pro.urlscan.com/api/v1/pro/search?filter=%%24phishing_%s" % kit["key"])
elif args.action == "showlatest":
    r = session.get("https://pro.urlscan.com/api/v1/pro/search?q=%s&filter=$phishing_%s&size=%d" % (query, args.brand, args.limit))
    print("\nSearching for brand '%s' with query '%s' and limit '%d'" % (args.brand, query, args.limit))
    print("Show in Pro: https://pro.urlscan.com/search?query=%s&filter=$phishing_%s" % (query, args.brand))
    if not r.status_code == requests.codes.ok:
        logging.error("Error fetching brand definitions: %s" % r.json())
        sys.exit(1)
    print("%d/%d results returned\n\n" % (len(r.json()["results"]), r.json()["total"]))
    for res in r.json()["results"]:
Esempio n. 6
0
 def parse_app_name(self):
     """Parse app name form apk."""
     parse_data = self.get_aapt_parse_data('application-label')
     app_name = _.head(parse_data) if parse_data else ''
     return app_name.decode("utf8")
Esempio n. 7
0
def pr_number_from_subject(commit_subject: str):
    pr_number = _.head(re.findall(r"Merge pull request #(\d+)",
                                  commit_subject))
    if not pr_number:  # Squash commit
        pr_number = _.head(re.findall(r" \(#(\d+)\)$", commit_subject))
    return pr_number