Glanceway Glanceway
सभी सोर्स

GitHub Trending

डेवलपर v1.0.0

Trending repositories on GitHub

@codytseng #github #trending #programming

कॉन्फ़िगरेशन

नाम कुंजी प्रकार आवश्यक डिफ़ॉल्ट विवरण
Language LANGUAGE string नहीं Filter by programming language (e.g., javascript, python). Leave empty for all languages.

सोर्स कोड

version: 1.0.0
name: GitHub Trending
description: Trending repositories on GitHub
author: codytseng
author_url: https://github.com/codytseng
category: Developer
tags:
  - github
  - trending
  - programming

config:
  - key: LANGUAGE
    name: Language
    type: string
    required: false
    description: Filter by programming language (e.g., javascript, python). Leave empty for all languages.
module.exports = async (api) => {
  const language = api.config.get("LANGUAGE");

  async function fetchData() {
    const since = new Date();
    since.setDate(since.getDate() - 7);
    const sinceStr = since.toISOString().split("T")[0];

    let query = `created:>${sinceStr} stars:>5`;
    if (language) {
      query += ` language:${language}`;
    }

    const response = await api.fetch(
      `https://api.github.com/search/repositories?q=${encodeURIComponent(query)}&sort=stars&order=desc&per_page=100`,
    );

    if (!response.ok || !response.json) {
      throw new Error(`Failed to fetch GitHub trending repositories (HTTP ${response.status})`);
    }

    api.emit(
      response.json.items.map((repo) => {
        return {
          id: repo.id.toString(),
          title: repo.full_name,
          subtitle: repo.description || `${repo.language ?? "Unknown"} · ${repo.stargazers_count} stars`,
          url: repo.html_url,
        };
      }),
    );
  }

  await fetchData();

  return {
    refresh: fetchData,
  };
};