itlsoft / lb

0 stars 0 forks source link

Github Rest #6

Open itlsoft opened 8 months ago

itlsoft commented 8 months ago

Tak, można uzyskać informacje o repozytoriach bez konieczności klonowania ich lokalnie, korzystając z GitHub REST API. To o wiele bardziej wydajne podejście, które nie wymaga pobierania całych repozytoriów na lokalny dysk. W Pythonie możesz użyć bibliotek takich jak requests, aby wykonać zapytania do API GitHub. Oto jak można to zrobić:

import requests
import pandas as pd

def get_github_repo_info(username, github_url):
    # Tworzenie listy repozytoriów użytkownika
    repos_url = f"{github_url}/api/v3/users/{username}/repos"
    response = requests.get(repos_url)
    if response.status_code != 200:
        print(f"Nie udało się pobrać repozytoriów użytkownika {username}")
        return None
    repositories = response.json()

    # Inicjalizacja pustego DataFrame do przechowywania informacji o repozytoriach
    repo_data = pd.DataFrame(columns=["Nazwa repozytorium", "Opis", "Data ostatniego commita", "Autor ostatniego commita", "Treść ostatniego commita"])

    for repo in repositories:
        repo_name = repo["name"]
        repo_description = repo["description"]

        # Pobieranie informacji o ostatnim commicie
        commits_url = f"{repo['url']}/commits?per_page=1&sha=main"
        commit_response = requests.get(commits_url)
        if commit_response.status_code == 200:
            last_commit = commit_response.json()[0]
            last_commit_date = last_commit["commit"]["committer"]["date"]
            last_commit_author = last_commit["commit"]["committer"]["name"]
            last_commit_message = last_commit["commit"]["message"]
        else:
            last_commit_date = "N/A"
            last_commit_author = "N/A"
            last_commit_message = "N/A"

        # Dodanie informacji do DataFrame
        repo_data = repo_data.append({"Nazwa repozytorium": repo_name, "Opis": repo_description, "Data ostatniego commita": last_commit_date, "Autor ostatniego commita": last_commit_author, "Treść ostatniego commita": last_commit_message}, ignore_index=True)

    return repo_data

if __name__ == "__main__":
    username = "ProjectX"
    github_url = "https://www.projekty.com/ProjectX"

    df = get_github_repo_info(username, github_url)
    if df is not None:
        print(df)

W powyższym kodzie używamy GitHub REST API do pobrania informacji o repozytoriach użytkownika ProjectX, a następnie zbieramy potrzebne dane i zapisujemy je do pandas DataFrame. Nie jest konieczne klonowanie repozytoriów, co sprawia, że operacja jest znacznie szybsza i bardziej efektywna.

itlsoft commented 8 months ago

import requests import json

def get_github_repo_info(username, github_url):

Tworzenie listy repozytoriów użytkownika

repos_url = f"{github_url}/api/v3/users/{username}/repos"
response = requests.get(repos_url)
if response.status_code != 200:
    print(f"Nie udało się pobrać repozytoriów użytkownika {username}")
    return None
repositories = response.json()

# Inicjalizacja pustego słownika do przechowywania informacji o repozytoriach w formie JSON
repo_data = []

for repo in repositories:
    repo_name = repo["name"]
    repo_description = repo["description"]

    # Pobieranie informacji o ostatnim commicie
    commits_url = f"{repo['url']}/commits?per_page=1&sha=main"
    commit_response = requests.get(commits_url)
    if commit_response.status_code == 200:
        last_commit = commit_response.json()[0]
        last_commit_date = last_commit["commit"]["committer"]["date"]
        last_commit_author = last_commit["commit"]["committer"]["name"]
        last_commit_message = last_commit["commit"]["message"]
    else:
        last_commit_date = "N/A"
        last_commit_author = "N/A"
        last_commit_message = "N/A"

    # Dodawanie informacji do listy w formacie JSON
    repo_info = {
        "Nazwa repozytorium": repo_name,
        "Opis": repo_description,
        "Data ostatniego commita": last_commit_date,
        "Autor ostatniego commita": last_commit_author,
        "Treść ostatniego commita": last_commit_message
    }
    repo_data.append(repo_info)

return json.dumps(repo_data, indent=4)

if name == "main": username = "ProjectX" github_url = "https://www.projekty.com/ProjectX"

repo_data_json = get_github_repo_info(username, github_url)
if repo_data_json is not None:
    print(repo_data_json)
itlsoft commented 8 months ago
$(document).on('click', function (event) {
  if (!$(event.target).hasClass('more')) {
    $('.dropout.active').removeClass('active');
  }
});

$('table').on('click', '.more', function (event) {
  event.stopPropagation(); // Zapobiegnij propagacji kliknięcia, aby uniknąć zamknięcia menu po kliknięciu w button
  var parentRow = $(this).parent();

  // Zamykanie innych otwartych menu
  $('.dropout.active').not(parentRow).removeClass('active');

  parentRow.toggleClass('active');
});
itlsoft commented 4 months ago

263152560_572220070743989_6930834203008111100_n