Exemple #1
0
def add_label(repo: Repository, label_filter,label_to_add: Label):
    """Add hacktoberfest label to all issues labeled with filter label."""
    if label_filter!=None:
        issues_list = repo.get_issues(state="open",labels=[label_filter])
    else:
        issues_list = repo.get_issues(state="open")
    for issue in issues_list:
        issue.add_to_labels(label_to_add)
    print('Hacktoberfest label added')
Exemple #2
0
def process_milestone(
    repo: Repository,
    milestone: Milestone,
    in_progress_label: Optional[Label],
    blocked_label: Optional[Label],
) -> str:
    now = datetime.now()
    html_url = milestone._rawData["html_url"]  # type: ignore
    total_issues = milestone.open_issues + milestone.closed_issues
    percentage_complete = as_percentage(milestone.closed_issues, total_issues)

    detail_lines = []

    status_line = f":heavy_check_mark: {percentage_complete}% completed"
    if in_progress_label:
        in_progress_issues = list(
            repo.get_issues(
                milestone=milestone, labels=[in_progress_label], state="open"
            )
        )
        if in_progress_issues:
            percentage_in_progress = as_percentage(
                len(in_progress_issues), total_issues
            )
            status_line += (
                f" - :hourglass_flowing_sand: {percentage_in_progress}% in progress"
            )
    if blocked_label:
        blocked_issues = list(
            repo.get_issues(milestone=milestone, labels=[blocked_label], state="open")
        )
        if blocked_issues:
            percentage_blocked = as_percentage(len(blocked_issues), total_issues)
            status_line += f" - :octagonal_sign: {percentage_blocked}% blocked"
    detail_lines.append(status_line)

    if milestone.due_on:
        duration = milestone.due_on - milestone.created_at
        remaining = milestone.due_on - now
        time_used = 100 - as_percentage(remaining.days, duration.days)
        detail_lines.append(
            f":date: {milestone.due_on.date().isoformat()} - :alarm_clock: {time_used}% time used"
        )

    rendered_line = (
        f"<{html_url}|{milestone.title}> - {milestone.closed_issues}/{total_issues}"
    )
    for line in detail_lines:
        rendered_line += f"\n\t{line}"

    return rendered_line
Exemple #3
0
def analyse_issues(project: Repository,
                   prev_issues: Dict[str, Any]) -> Dict[str, Any]:
    """Analyse of every closed issue in repository.

    Arguments:
        project {Repository} -- currently the PyGithub lib is used because of its functionality
                                ogr unfortunatelly did not provide enough to properly analyze issues

        project_knowledge {Path} -- project directory where the issues knowledge will be stored

    """
    _LOGGER.info("-------------Issues (that are not PR) Analysis-------------")

    current_issues = [
        issue for issue in project.get_issues(state="closed")
        if issue.pull_request is None
    ]
    new_issues = get_only_new_entities(prev_issues, current_issues)

    if len(new_issues) == 0:
        return

    with Knowledge(entity_type="Issue",
                   new_entities=new_issues,
                   accumulator=prev_issues,
                   store_method=store_issue) as analysis:
        accumulated = analysis.store()
    return accumulated
Exemple #4
0
    def analyse_issues(self,
                       repository: Repository,
                       prev_knowledge: Dict[str, Any],
                       is_local: bool = False) -> Dict[str, Any]:
        """Analyse of every closed issue in repository.

        Arguments:
            repository {Repository} -- currently the PyGithub lib is used because of its functionality
                                    ogr unfortunatelly did not provide enough to properly analyze issues

            prev_knowledge {Dict[str, Any]} -- previous knowledge stored

        """
        _LOGGER.info(
            "-------------Issues (that are not PR) Analysis-------------")

        current_issues = [
            issue for issue in repository.get_issues(state="all")
            if issue.pull_request is None
        ]
        new_issues = self.get_only_new_entities(prev_knowledge, current_issues)

        if len(new_issues) == 0:
            return

        with KnowledgeAnalysis(
                entity_type=EntityTypeEnum.ISSUE.value,
                new_entities=new_issues,
                accumulator=prev_knowledge,
                store_method=self.store_issue,
        ) as analysis:
            accumulated = analysis.store()

        return accumulated
Exemple #5
0
 def replace_label_with_existent(repo: Repository.Repository,
                                 previous_label: Label.Label,
                                 new_label_name: str):
     """
     Updates all issues containing a label with its replacement and then removes the replaced one.
     """
     print(f" Replacing {previous_label.name} from all issues")
     issues = repo.get_issues(labels=[previous_label])
     for issue in issues:
         try:
             issue.add_to_labels(new_label_name)
         except Exception as e:
             print(
                 f" Error adding label '{new_label_name}' to issue #{issue.number}"
             )
     LabelHook.delete_label(previous_label)
Exemple #6
0
def get_watchdog_issues(repo: Repository) -> dict[str, Issue]:
    """Query repository for watchdog issues

    Parameters
    ----------
    repo : Repository
        The repository to query

    Returns
    -------
    dict[str, Issue]
        The issues
    """
    watchdog_issues = {}
    issues = repo.get_issues(state="all", creator="rbuffat")
    for issue in issues:
        if "[Watchdog]" in issue.title:
            imagery_path = re.search(r"sources(.*?)geojson",
                                     issue.title).group(0)
            watchdog_issues[imagery_path] = issue
    return watchdog_issues
Exemple #7
0
def remove_label(repo: Repository):
    """Remove label from all issues with it."""
    issues_list = repo.get_issues(state="open", labels=['hacktoberfest'])
    for issue in issues_list:
        issue.remove_from_labels("hacktoberfest")
Exemple #8
0
def add_label(repo: Repository, filter_label_names: List[str], label_to_add: Label):
    """Add given label to all issues labeled with filter label."""
    issues_list = repo.get_issues(state="open", labels=filter_label_names)
    for issue in issues_list:
        issue.add_to_labels(label_to_add)
Exemple #9
0
def remove_label(repo: Repository, edit_label: str):
    """Remove label from all issues with it."""
    issues_list = repo.get_issues(state="open", labels=[edit_label])
    for issue in issues_list:
        issue.remove_from_labels(edit_label)