PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/DDG/Spice/Github.pm

http://github.com/duckduckgo/zeroclickinfo-spice
Perl | 44 lines | 28 code | 10 blank | 6 comment | 3 complexity | 10c0f02d936224447bf8d85a16d08806 MD5 | raw file
Possible License(s): Apache-2.0
  1. package DDG::Spice::Github;
  2. # ABSTRACT: Search for information about GitHub repositories
  3. use strict;
  4. use DDG::Spice;
  5. use Text::Trim;
  6. triggers startend => "github";
  7. my @triggers = share("triggers.txt")->slurp;
  8. triggers startend => "github";
  9. chomp(@triggers);
  10. my $langs = join("|", map(quotemeta, @triggers));
  11. spice to => 'https://api.github.com/search/repositories?q=$1&sort=stars&callback={{callback}}';
  12. spice proxy_cache_valid => '200 1d';
  13. handle query_lc => sub {
  14. s/^github\s*|\s+github$//;
  15. if ($_ eq "" || m/\bjobs\b|\bstatus\b|\bissue\b/) {
  16. return;
  17. }
  18. my $query = $_;
  19. my $l;
  20. # can't use standard \b word boundary here. It will fail for languages with characters like c++
  21. if (/ ($langs) / or /^($langs) / or / ($langs)$/) {
  22. $l = $1;
  23. $query =~ s/ ($langs) |^($langs) | ($langs)$//;
  24. # make sure there is an actual query, and not just a language term search
  25. trim($query); # need to add `use String::Trim`
  26. s/\s+/ /g; # squash down multiple spaces
  27. return unless length $_;
  28. # These is no separate language parameter for the query to
  29. # Github. You specify language as a part of the raw query string
  30. # passed to the api like on the web form interface.
  31. return "${query} language:\"${l}\"" unless /^jobs\b|\bjobs$|^status\b|\bstatus$|^issue\b|\bissue$/;
  32. }
  33. };
  34. 1;