Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ⚠️ for deprecated entry #517

Merged
merged 6 commits into from
Sep 7, 2020

Conversation

AristoChen
Copy link
Collaborator

Hi,

I think this commit change lots of entry, so I guess I should create a PR instead of push to upstream directly.

So here is the story, I wrote a python code(still not a rust expert 😂) to iterate through all entry, and use github api to check the date for latest commit. I found that there are 102 github repos that was not updated for more than 6 months(I use 180 days as criteria in my code currently), which meets the criteria of deprecated

Here is the list:

Repo: https://github.com/codecombat/aether                                  , latest commit date is: 2018-06-29T14:27:21Z
Repo: https://github.com/passy/android-lint-summary                         , latest commit date is: 2017-12-09T22:27:14Z
Repo: https://github.com/Glavin001/atom-beautify                            , latest commit date is: 2019-07-20T22:37:34Z
Repo: https://github.com/hchasestevens/bellybutton                          , latest commit date is: 2019-12-11T13:34:33Z
Repo: https://github.com/square/cane                                        , latest commit date is: 2018-01-10T04:36:59Z
Repo: https://github.com/mrtazz/checkmake                                   , latest commit date is: 2020-02-26T20:51:06Z
Repo: https://github.com/ContinuumIO/ciocheck                               , latest commit date is: 2017-01-21T23:17:36Z
Repo: https://github.com/dspinellis/ckjm                                    , latest commit date is: 2019-02-27T06:04:54Z
Repo: https://github.com/MetricsGrimoire/CMetrics                           , latest commit date is: 2012-07-16T07:37:24Z
Repo: https://github.com/code-cracker/code-cracker                          , latest commit date is: 2019-11-21T17:41:30Z
Repo: https://github.com/groupon/codeburner                                 , latest commit date is: 2018-11-08T17:07:34Z
Repo: https://github.com/clutchski/coffeelint                               , latest commit date is: 2018-02-16T07:32:30Z
Repo: https://github.com/mschwager/cohesion                                 , latest commit date is: 2019-08-01T08:46:36Z
Repo: https://github.com/banyanops/collector                                , latest commit date is: 2019-08-23T16:53:50Z
Repo: https://github.com/xcatliu/cqc                                        , latest commit date is: 2017-12-05T04:05:38Z
Repo: https://github.com/DustinCampbell/CSharpEssentials                    , latest commit date is: 2015-09-04T22:11:42Z
Repo: https://github.com/cssstats/cssstats                                  , latest commit date is: 2020-02-18T20:27:33Z
Repo: https://github.com/csscomb/csscomb.js                                 , latest commit date is: 2019-06-24T12:51:43Z
Repo: https://github.com/CSSLint/csslint                                    , latest commit date is: 2019-02-21T01:35:18Z
Repo: https://github.com/MangoTheCat/cyclocomp                              , latest commit date is: 2016-11-09T13:32:05Z
Repo: https://github.com/eliasgranderubio/dagda                             , latest commit date is: 2020-02-25T18:31:50Z
Repo: https://github.com/thesp0nge/dawnscanner                              , latest commit date is: 2018-11-30T16:00:30Z
Repo: https://github.com/tsenart/deadcode                                   , latest commit date is: 2016-07-24T21:28:37Z
Repo: https://github.com/sensiolabs-de/deprecation-detector                 , latest commit date is: 2017-09-06T12:14:01Z
Repo: https://github.com/Halleck45/DesignPatternDetector                    , latest commit date is: 2015-12-14T08:55:47Z
Repo: https://github.com/nickng/dingo-hunter                                , latest commit date is: 2019-03-13T23:31:52Z
Repo: https://github.com/garethr/docker-label-inspector                     , latest commit date is: 2015-11-08T19:15:45Z
Repo: https://github.com/alexkohler/dogsled                                 , latest commit date is: 2018-11-08T11:28:31Z
Repo: https://github.com/mibk/dupl                                          , latest commit date is: 2018-10-11T11:49:44Z
Repo: https://github.com/Kha/electrolysis                                   , latest commit date is: 2017-03-06T09:41:12Z
Repo: https://github.com/jared-stilwell/escomplex                           , latest commit date is: 2017-07-20T18:06:17Z
Repo: https://github.com/jquery/esprima                                     , latest commit date is: 2019-11-08T09:57:51Z
Repo: https://github.com/david-a-wheeler/flawfinder                         , latest commit date is: 2020-02-17T15:24:34Z
Repo: https://github.com/seattlerb/flay                                     , latest commit date is: 2019-10-09T02:07:04Z
Repo: https://github.com/lafolle/flen                                       , latest commit date is: 2018-03-11T06:23:46Z
Repo: https://github.com/JossWhittle/FlintPlusPlus                          , latest commit date is: 2018-04-06T22:24:59Z
Repo: https://github.com/seattlerb/flog                                     , latest commit date is: 2020-02-08T22:57:56Z
Repo: https://github.com/yandex/gixy                                        , latest commit date is: 2020-01-09T01:49:37Z
Repo: https://github.com/leighmcculloch/gochecknoglobals                    , latest commit date is: 2019-03-06T16:23:14Z
Repo: https://github.com/jgautheron/goconst                                 , latest commit date is: 2020-02-27T15:08:35Z
Repo: https://github.com/fzipp/gocyclo                                      , latest commit date is: 2015-06-27T05:31:10Z
Repo: https://github.com/mangothecat/goodpractice                           , latest commit date is: 2019-10-16T16:01:54Z
Repo: https://github.com/360EntSecGroup-Skylar/goreporter                   , latest commit date is: 2018-09-02T11:56:03Z
Repo: https://github.com/linuxerwang/goroutine-inspect                      , latest commit date is: 2018-10-27T04:51:11Z
Repo: https://github.com/TheJaredWilcurt/itcss-specificity-graph            , latest commit date is: 2019-02-06T22:07:11Z
Repo: https://github.com/mcarton/rust-herbie-lint                           , latest commit date is: 2016-08-28T17:53:48Z
Repo: https://github.com/htacg/tidy-html5                                   , latest commit date is: 2019-07-08T18:52:14Z
Repo: https://github.com/nasa-sw-vnv/ikos                                   , latest commit date is: 2019-12-12T22:21:55Z
Repo: https://github.com/justinabrahms/imhotep                              , latest commit date is: 2017-12-09T20:00:47Z
Repo: https://github.com/feddischson/include_gardener                       , latest commit date is: 2019-11-17T20:02:37Z
Repo: https://github.com/feddischson/include_gardener                       , latest commit date is: 2019-11-17T20:02:37Z
Repo: https://github.com/feddischson/include_gardener                       , latest commit date is: 2019-11-17T20:02:37Z
Repo: https://github.com/jkinder/jakstab                                    , latest commit date is: 2019-12-10T09:41:29Z
Repo: https://github.com/HairyFotr/linter                                   , latest commit date is: 2016-12-08T22:48:02Z
Repo: https://github.com/AtomLinter/linter-rust                             , latest commit date is: 2020-02-11T22:25:53Z
Repo: https://github.com/Debian/lintian                                     , latest commit date is: 2017-07-23T06:08:45Z
Repo: https://github.com/lyft/linty_fresh                                   , latest commit date is: 2019-03-19T17:35:45Z
Repo: https://github.com/walle/lll                                          , latest commit date is: 2019-08-16T13:02:02Z
Repo: https://github.com/mpeterv/luacheck                                   , latest commit date is: 2018-10-11T21:47:39Z
Repo: https://github.com/mdempsky/maligned                                  , latest commit date is: 2018-07-07T21:12:28Z
Repo: https://github.com/client9/misspell                                   , latest commit date is: 2018-03-09T02:03:25Z
Repo: https://github.com/Trismegiste/Mondrian                               , latest commit date is: 2014-09-16T13:23:02Z
Repo: https://github.com/alexkohler/nakedret                                , latest commit date is: 2020-01-28T12:33:11Z
Repo: https://github.com/GeoffreyHecht/paprika                              , latest commit date is: 2018-03-19T20:14:40Z
Repo: https://github.com/katiefenn/parker                                   , latest commit date is: 2016-07-27T14:09:37Z
Repo: https://github.com/psecio/parse                                       , latest commit date is: 2018-08-01T18:12:46Z
Repo: https://github.com/codegram/pelusa                                    , latest commit date is: 2015-01-07T08:10:08Z
Repo: https://github.com/rskuipers/php-assumptions                          , latest commit date is: 2019-04-04T07:11:49Z
Repo: https://github.com/QafooLabs/php-refactoring-browser                  , latest commit date is: 2015-04-14T11:32:09Z
Repo: https://github.com/Andrewsville/PHP-Token-Reflection                  , latest commit date is: 2014-08-06T16:37:44Z
Repo: https://github.com/wapmorgan/PhpCodeAnalyzer                          , latest commit date is: 2019-05-09T15:24:55Z
Repo: https://github.com/mamuz/PhpDependencyAnalysis                        , latest commit date is: 2019-10-16T05:18:51Z
Repo: https://github.com/dunglas/phpdoc-to-typehint                         , latest commit date is: 2017-12-20T14:04:16Z
Repo: https://github.com/EdgedesignCZ/phpqa                                 , latest commit date is: 2020-02-02T12:14:47Z
Repo: https://github.com/jmolivas/phpqa                                     , latest commit date is: 2017-12-07T21:31:54Z
Repo: https://github.com/ovr/phpsa                                          , latest commit date is: 2019-02-27T06:40:35Z
Repo: https://github.com/rodjek/puppet-lint                                 , latest commit date is: 2020-02-15T22:15:34Z
Repo: https://github.com/regebro/pyroma                                     , latest commit date is: 2019-11-02T15:01:27Z
Repo: https://github.com/Qafoo/QualityAnalyzer                              , latest commit date is: 2019-12-04T07:45:28Z
Repo: https://github.com/linkedin/qark                                      , latest commit date is: 2019-04-05T05:07:04Z
Repo: https://github.com/apiology/quality                                   , latest commit date is: 2020-01-05T02:17:10Z
Repo: https://github.com/teamed/qulice                                      , latest commit date is: 2019-12-12T20:13:06Z
Repo: https://github.com/david-a-wheeler/railroader                         , latest commit date is: 2020-01-24T20:35:34Z
Repo: https://github.com/icsharpcode/RefactoringEssentials                  , latest commit date is: 2019-10-11T17:55:39Z
Repo: https://github.com/stripe/safesql                                     , latest commit date is: 2019-09-10T22:49:40Z
Repo: https://github.com/scalastyle/scalastyle                              , latest commit date is: 2019-03-04T20:14:47Z
Repo: https://github.com/duaraghav8/Solium                                  , latest commit date is: 2019-09-14T06:33:06Z
Repo: https://github.com/pocketjoso/specificity-graph                       , latest commit date is: 2016-04-16T07:21:52Z
Repo: https://github.com/ravenexp/splint                                    , latest commit date is: 2019-08-03T23:38:15Z
Repo: https://github.com/purcell/sqlint                                     , latest commit date is: 2020-02-11T21:29:48Z
Repo: https://github.com/StanfordPL/stoke                                   , latest commit date is: 2019-10-03T15:54:12Z
Repo: https://github.com/Tencent/TscanCode                                  , latest commit date is: 2018-12-10T09:57:07Z
Repo: https://github.com/Glavin001/tslint-clean-code                        , latest commit date is: 2019-09-14T00:35:35Z
Repo: https://github.com/Microsoft/tslint-microsoft-contrib                 , latest commit date is: 2019-07-29T09:34:57Z
Repo: https://github.com/ashleyglee/TSqlRules                               , latest commit date is: 2017-02-21T18:15:41Z
Repo: https://github.com/ircmaxell/Tuli                                     , latest commit date is: 2015-10-23T17:55:58Z
Repo: https://github.com/asm89/twig-lint                                    , latest commit date is: 2016-12-30T10:04:11Z
Repo: https://github.com/mdempsky/unconvert                                 , latest commit date is: 2020-02-28T14:31:38Z
Repo: https://github.com/Yelp/undebt                                        , latest commit date is: 2017-07-09T23:25:22Z
Repo: https://github.com/alexkohler/unimport                                , latest commit date is: 2017-11-06T22:33:08Z
Repo: https://github.com/Vannevelj/VSDiagnostics                            , latest commit date is: 2019-04-21T17:04:28Z
Repo: https://github.com/Wintellect/Wintellect.Analyzers                    , latest commit date is: 2016-02-29T02:21:22Z

so maybe I will run my python code every month to update the deprecated status from now on, let me know if have any thoughts, Thanks :)

@Amar1729
Copy link
Collaborator

Neat! If merged, you could even trigger this via GitHub Actions, since they can run on a schedule.

@mre
Copy link
Member

mre commented Aug 26, 2020

First off, wow that's a great idea that hadn't crossed my mind before.
I agree with @Amar1729 that this could even be part of our CI process.

The 6 months were picked somewhat arbitrarily and I can see how it might be a bit too harsh for the beginning.
At least I for one maintain a few projects that haven't been updated in 6 months and that I still consider "maintained". 😉
Also, there might be projects that use a different development branch, such as next or devel and only use the master for stable releases.

All in all, I'd lower the threshold a bit to 2 years for now as this would deprecate quite a few tools in one go already. We could increase the threshold later if we see fit.

Alternatively, we could add a new, automated, field to our yaml: last_updated. Of course, for some projects like proprietary web-services this might be "unknown", but for most it would be nice to have and to show on the website.
Then our rule for deprecation would become if tool.last_updated < THRESHOLD { "⚠️" }.

What do you both think?
Also like to hear @jakubsacha's position on this if he finds the time.

@jakubsacha
Copy link
Contributor

Hey,

This is very nice idea. I also think that 6 months is a bit to harsh. For me a year seems good, but i'm fine with 2 years as well.

Speaking of adding such a tool to CI pipeline: since readme is generated with rust, maybe we would stick to that language and write a deprecated checked is rust as well?

btw, i'd really like to merge this PR before: #484 goes to master.

@AristoChen
Copy link
Collaborator Author

Hi,

Thank you guys for the thoughts!

For the criteria of deprecated, one year or two years are both ok for me.

And for the CI part, that was indeed a good suggestion, at least I don't need to run it manually every time to update the status. Currently, I am still very very new to rust, so that's the reason why I wrote python code😂, but I am willing to learn using rust to do the same thing.

I tried to google someting about making http request in rust, and I found that there is one thing called reqwest, which seems to be popular for doing this kind of thing. What I have in my mind currently is like this:

  • Create a function(something like pub fn check_deprecated(entries: &Vec<Entry>)) in lib.rs
  • This function will be called in main.rs after calling validate(&tags, &tools)?;
  • This function will iterate through all entries that contains source
  • Make sure source is a valid github url, then call github api
  • Try to parse the result into json format, then compare the date of latest commit with current date
  • If the latest commit date is 2 years ago, then mark this entry as deprecated

Not sure if this make any sense to you guys, please forgive me if I misunderstood anything, any suggestion will be appreciated!

BTW, according to this document, calling github api is limited to 60 times per hour for unauthenticated requests. I used my personal authentication token in my python code, but it seems a bit weird if I use it here in rust code, any idea about this?

@mre
Copy link
Member

mre commented Aug 27, 2020

For the criteria of deprecated, one year or two years are both ok for me.

Let's go with one year then. 😊

but I am willing to learn using rust to do the same thing.

Cool!

Your plan sounds good. I'd do the same, basically.
I did something very similar recently, where I wrote a link checker with special Github support.
Code is here.
There's also a video about it if you're more like the visual type.
Heads up: I switched from github-rs to hubcaps as it was easier to use and more up-to-date. You can pass in a Github token and it will greatly help with the rate limiter.

We can have a coding session when you have time and I could mentor you if you like. 👍

@AristoChen
Copy link
Collaborator Author

Let's go with one year then. 😊

No problem.

Thanks a lot for providing those resources, I just spent some time on it, and currently success to use hubcaps to call github api, will work on the rest of things next week after get off work.💪

We can have a coding session when you have time and I could mentor you if you like. 👍

Thanks a lot in advance, but I prefer to do it by myself first, will let you know if I need help.😄

@AristoChen
Copy link
Collaborator Author

Hi,

Almost completed, but it seems that hubcaps got some issue. Some of the github repo were not able to get commit list by using hubcaps.

Here are part of repos that will fail:

https://github.com/TNG/ArchUnit
https://github.com/PyCQA/bandit
https://github.com/ambv/black
https://github.com/timakin/bodyclose
https://github.com/dspinellis/ckjm
https://github.com/coreos/clair

I used the sample code here, and filled in my own personal token, then replacing

let commits = github.repo("softprops", "hubcaps").commits().list().await?;

with

let commits = github.repo("TNG", "ArchUnit").commits().list().await?;

The error message is Error: Codec(Error("invalid type: null, expected struct User", line: 1, column: 67983)). The error message is really similar if using some other repo that I mentioned above.

What I will do next is to find some other methods to replace hubcaps, any suggestion will be appreciated!

@mre
Copy link
Member

mre commented Sep 2, 2020

Thanks for the progress report @AristoChen,
if you find the time, could you open an issue on hubcaps to track this problem?
There is a similar issue here, but it wasn't resolved.
I am confident that you'll get some quick help over there, though.

@mre
Copy link
Member

mre commented Sep 2, 2020

Just confirming that it does work from the commandline:

curl https://api.github.com/repos/TNG/ArchUnit/commits

yields the correct commits for me.
Was thinking that it was a case of a moved repository (to a new organization), but nope.

@mre
Copy link
Member

mre commented Sep 2, 2020

Just some more observations:

  • the error results from serde, which is used for deserializing the API request. Looks like you get a null pointer back where you expect a User struct. So there seems to be a case where the User field isnull and indeed I could find one commit per repo where this is the case.
  {
    "sha": "c395bc282b6c52feb0165a1657086d711547829f",
    "node_id": "MDY6Q29tbWl0ODg5NjIwNDI6YzM5NWJjMjgyYjZjNTJmZWIwMTY1YTE2NTcwODZkNzExNTQ3ODI5Zg==",
    "commit": {
      "author": {
        "name": "ldebruijn",
        "email": "[email protected]",
        "date": "2020-06-09T21:12:49Z"
      },
      "committer": {
        "name": "Peter Gafert",
        "email": "[email protected]",
        "date": "2020-06-18T19:44:25Z"
      },
      "message": "Prevent excessive logging when supplying system properties by only logging if the system properties have changed\n\nSigned-off-by: ldebruijn <[email protected]>",
      "tree": {
        "sha": "6e8791ea22ad8a0112581fb521eeb0741933f96a",
        "url": "https://api.github.com/repos/TNG/ArchUnit/git/trees/6e8791ea22ad8a0112581fb521eeb0741933f96a"
      },
      "url": "https://api.github.com/repos/TNG/ArchUnit/git/commits/c395bc282b6c52feb0165a1657086d711547829f",
      "comment_count": 0,
      "verification": {
        "verified": false,
        "reason": "unsigned",
        "signature": null,
        "payload": null
      }
    },
    "url": "https://api.github.com/repos/TNG/ArchUnit/commits/c395bc282b6c52feb0165a1657086d711547829f",
    "html_url": "https://github.com/TNG/ArchUnit/commit/c395bc282b6c52feb0165a1657086d711547829f",
    "comments_url": "https://api.github.com/repos/TNG/ArchUnit/commits/c395bc282b6c52feb0165a1657086d711547829f/comments",
    "author": null,
    "committer": {
      "login": "codecholeric",
      "id": 4095015,
      "node_id": "MDQ6VXNlcjQwOTUwMTU=",
      "avatar_url": "https://avatars3.githubusercontent.com/u/4095015?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/codecholeric",
      "html_url": "https://github.com/codecholeric",
      "followers_url": "https://api.github.com/users/codecholeric/followers",
      "following_url": "https://api.github.com/users/codecholeric/following{/other_user}",
      "gists_url": "https://api.github.com/users/codecholeric/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/codecholeric/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/codecholeric/subscriptions",
      "organizations_url": "https://api.github.com/users/codecholeric/orgs",
      "repos_url": "https://api.github.com/users/codecholeric/repos",
      "events_url": "https://api.github.com/users/codecholeric/events{/privacy}",
      "received_events_url": "https://api.github.com/users/codecholeric/received_events",
      "type": "User",
      "site_admin": false
    },
    "parents": [
      {
        "sha": "97e396a515cba46c9e0e64e8a527cb3254e93bfb",
        "url": "https://api.github.com/repos/TNG/ArchUnit/commits/97e396a515cba46c9e0e64e8a527cb3254e93bfb",
        "html_url": "https://github.com/TNG/ArchUnit/commit/97e396a515cba46c9e0e64e8a527cb3254e93bfb"
      }
    ]
  },

So I guess it could be fixed in a couple of ways:

  • The proper way is to make the author field either an Option<String>. I don't think this can be changed given the popularity of the crate, although it's still 0.x so breaking changes are still allowed without major interruption.
  • A quick fix is to only read the first commit and hope that you don't hit an empty one. Something like:
    let last_commit = let commits = github.repo("softprops", "hubcaps").commits().iter().first().await?; (The syntax is probably wrong but you get the idea.)

@mre
Copy link
Member

mre commented Sep 2, 2020

Created a bug report here. In the meantime the workaround should be fine. 😊

@mre
Copy link
Member

mre commented Sep 2, 2020

BTW this is the sample code for getting the last commit:

use anyhow::{anyhow, Result};
use futures::stream::StreamExt;
use hubcaps::{Credentials, Github};
use std::env;

#[tokio::main]
async fn main() -> Result<()> {
    let github = Github::new(
        String::from("user-agent-name"),
        env::var("GITHUB_TOKEN").ok().map(Credentials::Token),
    )?;

    let last_commit = github
        .repo("TNG", "ArchUnit")
        .commits()
        .iter()
        .next()
        .await
        .ok_or(anyhow!("No commit"));
    println!("{:?}", last_commit);

    Ok(())
}

It does not work and produces the same error. I think hubcaps is deserializing the entire API response and not only the first commit, but I might be wrong. Maybe you find a way to make it work somehow.

@mre
Copy link
Member

mre commented Sep 2, 2020

In the worst case we can just print the error and ignore these entries for now, e.g. we don't mark them as deprecated.

@AristoChen
Copy link
Collaborator Author

Hi,

Appreciate for all these help!

I have tried some other methods in my mind, but no luck to solve the error, so I decided to ignore those entries lol.

I still need some time to check the result is correct or not, so I think I will push the commit tomorrow evening, time to sleep in my country haha.

BTW, there is one more question that I wanna ask, it's about github token. Currently I wrote this in my code

let github = Github::new(
    String::from("AristoChen"),
    Credentials::Token(
        String::from("MY_OWN_PERSONAL_GITHUB_TOKEN")
    ),
)?;

And I notice that your comment here is

let github = Github::new(
    String::from("user-agent-name"),
    env::var("GITHUB_TOKEN").ok().map(Credentials::Token),
)?;

which seems to cause the rate limit problem, and I am still not sure how to solve this yet. I will try to figure this out after get off work tomorrow, any suggestions will be appreciated!

@mre
Copy link
Member

mre commented Sep 2, 2020

I'd go with this snippet, which I got from the official documentation:

let github = Github::new(
    String::from("user-agent-name"),
    env::var("GITHUB_TOKEN").ok().map(Credentials::Token),
)?;

The trick is that you have to set the token as an environment variable like so:

export GITHUB_TOKEN=your_token_here

After that you can run your program and it will pick up the token from the environment.
Once we run this on Github actions, the token will already be set. 😄

@AristoChen
Copy link
Collaborator Author

export GITHUB_TOKEN=your_token_here

Oh I got you, thanks a lot for this.

Still need some more time to check each result🔎

@AristoChen
Copy link
Collaborator Author

Hi,

Just completed!

I added one more thing, I will check whether GITHUB_TOKEN is set or not, if not, then bypass the checking function. I think it is better for other contributors that do not care about deprecated, because it will take around 4 minutes(on my PC) for checking each github entry.

Finally, THANKS A LOT for all these suggestions, I believe that there is something that could be handled in a better way, so if you find anything that seems not make sense, feel free to edit it! If possible, let me know what was edited as well, I’d like to know what is the better way 😄

Copy link
Contributor

@jakubsacha jakubsacha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice contribution, well done


let mut entries_tmp: Vec<Entry> = entries.to_vec();
for entry in &mut entries_tmp {
if entry.source.is_some() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer a bit more flat structure.

You can restructure this code to negate if condition here and put "continue" in it. That way you'll avoid multiple indentations.

This applies also to the if conditions that you put below.

@AristoChen
Copy link
Collaborator Author

Hi @jakubsacha,

Thanks for the suggestion! I edited the code, let me know if there is anything else 👍

@jakubsacha
Copy link
Contributor

👍 from my side. @mre ?

Copy link
Member

@mre mre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. I'm impressed that you pulled this off.
Added a few comments to make the code more idiomatic.

data/render/Cargo.toml Show resolved Hide resolved
data/render/src/bin/main.rs Show resolved Hide resolved
data/render/src/lib.rs Outdated Show resolved Hide resolved
let mut source: &str = entry.source.as_ref().unwrap();
if source.chars().last().unwrap() == '/' {
source = source.trim_end_matches('/');
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think those four lines can be replaced with one:

entry.source = entry.source.trim_end_matches('/');

The performance/memory overhead is negligible if that was a concern. 😊

Copy link
Collaborator Author

@AristoChen AristoChen Sep 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited like this, looks a bit long for the first line though

let components: Vec<&str> = entry.source.as_ref().unwrap().trim_end_matches('/').split("/").collect();
if !(components.contains(&"github.com") && components.len() == 5) {
    // valid github source must have 5 elements - anything longer and they are probably a
    // reference to a path inside a repo, rather than a repo itself.
    continue;
}

not sure if this make sense?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could refactor it a bit and put the extraction of owner and repo into a seprate function:

let (owner, repo) = analyze_repo_url(entry.source)?;

Code for the function:

fn analyze_repo_url(url: String) -> Result<(String, String), Box<dyn Error>> { 
  let components: Vec<&str> = url.trim_end_matches('/').split("/").collect();
  if !components.contains(&"github.com") || components.len() != 5 {
    // valid github source must have 5 elements - anything longer and they are probably a
    // reference to a path inside a repo, rather than a repo itself.
    return Err("Cannot extract owner and repo".into());
  }
  let owner = components[3];
  let repo  = components[4];
  Ok((owner.into(), repo.into()))
}

Completely optional, though. 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I didn't notice this comment before I push the commit

@mre If you prefer this way, I can edit the code and push another commit 😉

Credentials::Token(token),
)?;

let mut entries_tmp: Vec<Entry> = entries.to_vec();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the temporary allocation here? Ownership issues?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew it looks very weird, I have tried some methods, but using a temporary entries_tmp is the only one that success. I believe there are some better way to handle this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somehow managed to remove the temporary entries_tmp, still not really familiar with handling ownership in rust😵

let commit_list = match commit_list {
Ok(commit_list) => commit_list,
Err(_error) => Vec::new(),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this block:

        let commit_list = match commit_list {
            Ok(commit_list) => commit_list,
            Err(_error) => Vec::new(),
        };

fn main returns a result, so you can simply .await? (note the ?) in the line above.
Good stuff.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was originally using await?, but if some repo failed to get commit list, it will only gives me this error message

Error: Codec(Error("invalid type: null, expected struct User", line: 1, column: 67983))

and the program will directly exit, so thats the reason why I use that method to handle this error.

Not sure if there is any other way to handle this?

Copy link
Collaborator Author

@AristoChen AristoChen Sep 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make more sense than my original code?

        if let Ok(commit_list) = github
            .repo(owner, repo)
            .commits()
            .list()
            .await
        {
            let date = &commit_list[0].commit.author.date;
            let last_commit = NaiveDateTime::parse_from_str(&date, "%Y-%m-%dT%H:%M:%SZ")?;
            let last_commit_utc = DateTime::<Utc>::from_utc(last_commit, Utc);
            let duration = Local::today().signed_duration_since(last_commit_utc.date());

            if duration.num_days() > 365 {
                entry.deprecated = Some(true);
            } else {
                entry.deprecated = None;
            }
        }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's actually quite nice!

};
if commit_list.len() == 0 {
continue;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that check either. It will be redundant once we use the ? above. (See previous comment.)

data/render/src/lib.rs Outdated Show resolved Hide resolved
data/render/src/lib.rs Outdated Show resolved Hide resolved
data/render/src/lib.rs Outdated Show resolved Hide resolved
@AristoChen
Copy link
Collaborator Author

Hi,

THANKS A LOT for all those suggestions! Just completed the modification, please let me know if there is anything else 😄

@@ -21,6 +23,50 @@ pub fn validate(tags: &Tags, entries: &Vec<Entry>) -> Result<(), Box<dyn Error>>
Ok(())
}

#[tokio::main]
pub async fn check_deprecated(token: std::string::String, entries: &mut Vec<Entry>) -> Result<(), Box<dyn Error>> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string::String is part of the Rust prelude, which is a fancy way of saying you can just use String here without importing anything. 😎

@mre
Copy link
Member

mre commented Sep 7, 2020

Cool beans! Just mentioned one final but I think we're ready to merge. 👍 Feel free to push the big green button. 🕺

@mre
Copy link
Member

mre commented Sep 7, 2020

Let me take a moment to say that I really love the collaborative spirit around this project. Thanks for all the work from everybody. ⭐

@AristoChen
Copy link
Collaborator Author

Hi,

I replaced std::string::String with String.

If there is nothing else, I will click the big green button to merge PR later 😄

THANKS A LOT for all the help and suggestions, really glad to have this opportunity to collaborate with you guys!

@mre
Copy link
Member

mre commented Sep 7, 2020

THANKS A LOT for all the help and suggestions, really glad to have this opportunity to collaborate with you guys!

Same! Thanks for pushing through. Ready to merge. 😊

@AristoChen AristoChen merged commit 835c690 into analysis-tools-dev:master Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants