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

Feature/warn user on archived GitHub repos #244

Merged
merged 2 commits into from
May 30, 2024

Conversation

snim2
Copy link
Contributor

@snim2 snim2 commented May 28, 2024

Warn user if they pull from an archived GitHub repo

This commit issues a warning to the user if they clone or checkout from an
archived GitHub repository. In dxw, archiving a GitHub repository containing
a dependency is likely to mean that the repository will soon be removed, and
so we need to make users aware of this. However, we do not want to cause
an error here, because we do not know whether Whippet is being run in the
context of a local development environment or as part of a deploy process.

Note that because we are only enabling this feature for a specific dxw use case,
this commit does not make the effort to abstract out GitHub-specific code in
a way that would make it easy to generalise the feature for GitLab, BitBucket,
etc. This can be done in a future PR, if anyone needs it, but ideally we would
want to improve the unit tests before hand.

Testing

Create a whippet.json file with an archived repository, for example:

{
  "plugins": [
     {"name": "ht-body-exporter", "src": "https://github.com/dxw/ht-body-exporter"}
  ]
}

and run whippet deps update. Check that a warning is printed.

Remove the lockfile and create a new whippet.json with a non-archived reposistory, e.g.:

{
  "plugins": [
     {"name": "dxw-members-only", "src": "https://github.com/dxw/dxw-members-only"}
  ]
}

and run whippet deps update. Check that a warning is not printed.


  • Includes tests (if new features are introduced)
  • Commit message includes link to the ticket/issue
  • Changelog updated
  • PR open against dxw's Homebrew Tap to point the Whippet formula to the new version number

Copy link
Contributor

@RobjS RobjS left a comment

Choose a reason for hiding this comment

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

@snim2 I'm not seeing the warning. It looks like it's because that API requests are going to the incorrect URLs, e.g. it looks like it's going to https://api.github.com/repos/[email protected]:dxw/ht-body-exporter.git

@snim2
Copy link
Contributor Author

snim2 commented May 28, 2024

@snim2 I'm not seeing the warning. It looks like it's because that API requests are going to the incorrect URLs, e.g. it looks like it's going to https://api.github.com/repos/[email protected]:dxw/ht-body-exporter.git

What does your JSON file look like? I have:

{
  "plugins": [
     {"name": "ht-body-exporter", "src": "[email protected]:dxw/ht-body-exporter.git"}
  ]
}

and I get:

❯ whippet-test deps update
[Updating plugins/ht-body-exporter]
[Checking plugins/ht-body-exporter]
WARNING: GitHub repo is archived. This dependency should be replaced before the repo is removed.
HEAD is now at 3053e2e Initial commit
#############################################
#                                           #
#  WARNING: No inspections for this plugin  #
#                                           #
#############################################

@RobjS
Copy link
Contributor

RobjS commented May 28, 2024

This is by whippet.json:

{
  "src": {
    "plugins": "[email protected]:dxw-wordpress-plugins/"
  },
  "plugins": [
    { "name": "classic-editor" },
    { "name": "co-authors-plus" },
    {
        "name": "dxw-members-only",
        "src": "[email protected]:dxw/dxw-members-only.git"
    },
    { "name": "slack" },
    { "name": "notify-users-e-mail" },
    { "name": "parsedown-party" },
    {"name": "advanced-custom-fields-pro"},
    {"name": "ht-body-exporter", "src": "https://github.com/dxw/ht-body-exporter"}

  ],
  "themes": [
    {
      "name": "govpress-product-theme",
      "src": "[email protected]:dxw/govpress-product-theme.git"
    }
  ]
}

I used bikeshed's whippet file as an example. Whether I use the http or ssh reference for the archived repo, I get the same result. I've put in logging to confirm that the curl request is made, but it's getting 404-ed. e.g. (with my logging included)

[Checking plugins/ht-body-exporter]
Checking if archived...
API URL: https://api.github.com/repos/[email protected]:dxw/ht-body-exporter.git
Curl request sent
Curl response: object(stdClass)#58 (2) {
  ["message"]=>
  string(9) "Not Found"
  ["documentation_url"]=>
  string(57) "https://docs.github.com/rest/repos/repos#get-a-repository"
}
HEAD is now at 3053e2e Initial commit
#############################################
#                                           #
#  WARNING: No inspections for this plugin  #
#                                           #
#############################################

@snim2
Copy link
Contributor Author

snim2 commented May 28, 2024

I used bikeshed's whippet file as an example. Whether I use the http or ssh reference for the archived repo, I get the same result. I've put in logging to confirm that the curl request is made, but it's getting 404-ed. e.g. (with my logging included)

[Checking plugins/ht-body-exporter]
Checking if archived...
API URL: https://api.github.com/repos/[email protected]:dxw/ht-body-exporter.git
Curl request sent
Curl response: object(stdClass)#58 (2) {
  ["message"]=>
  string(9) "Not Found"
  ["documentation_url"]=>
  string(57) "https://docs.github.com/rest/repos/repos#get-a-repository"
}
HEAD is now at 3053e2e Initial commit
#############################################
#                                           #
#  WARNING: No inspections for this plugin  #
#                                           #
#############################################

So, this is what I get with that file:

...
[Checking plugins/ht-body-exporter]
WARNING: GitHub repo is archived. This dependency should be replaced before the repo is removed.
HEAD is now at 3053e2e Initial commit
...

and it still works if I copy over the Bikeshed files and add the new dependency. I'll investigate further...

@snim2
Copy link
Contributor Author

snim2 commented May 28, 2024

Cannot reproduce with PHP 8.2 or 8.3

@snim2
Copy link
Contributor Author

snim2 commented May 28, 2024

OK, so somehow I can reproduce the error for several repos but not this one...

@snim2 snim2 requested a review from RobjS May 28, 2024 13:36
Copy link
Contributor

@RobjS RobjS left a comment

Choose a reason for hiding this comment

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

This is working for me now, for both ssh and https repo references.

One non-blocking suggestion: do we want to format the warning along the lines of the "No inspections for this plugin" warning, so it's less easily missed?

@snim2
Copy link
Contributor Author

snim2 commented May 30, 2024

This is working for me now, for both ssh and https repo references.

One non-blocking suggestion: do we want to format the warning along the lines of the "No inspections for this plugin" warning, so it's less easily missed?

Yes, I think that's very wise!!!

@snim2
Copy link
Contributor Author

snim2 commented May 30, 2024

New look:

[Checking plugins/ht-body-exporter]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! WARNING: GitHub repo is archived. This dependency !!
!! should be replaced before the repo is removed.    !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
HEAD is now at 3053e2e Initial commit
#############################################
#                                           #
#  WARNING: No inspections for this plugin  #
#                                           #
#############################################

@snim2
Copy link
Contributor Author

snim2 commented May 30, 2024

Squashing before merge

snim2 added 2 commits May 30, 2024 17:25
This commit issues a warning to the user if they clone or checkout from an
archived GitHub repository. In dxw, archiving a GitHub repository containing
a dependency is likely to mean that the repository will soon be removed, and
so we need to make users aware of this. However, we do not want to cause
an error here, because we do not know whether Whippet is being run in the
context of a local development environment or as part of a deploy process.

Note that because we are only enabling this feature for a specific dxw use case,
this commit does not make the effort to abstract out GitHub-specific code in
a way that would make it easy to generalise the feature for GitLab, BitBucket,
etc. This can be done in a future PR, if anyone needs it, but ideally we would
want to improve the unit tests before hand.
@snim2 snim2 force-pushed the feature/warn-user-on-archived-github-repos branch from b038b8e to 08b4673 Compare May 30, 2024 16:25
@snim2 snim2 merged commit 19d6be6 into main May 30, 2024
5 checks passed
@snim2 snim2 deleted the feature/warn-user-on-archived-github-repos branch May 30, 2024 16:26
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.

2 participants