Giter Site home page Giter Site logo

rybak / copy-commit-reference-userscript Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 592 KB

Userscripts to add a "Copy commit reference" button to commit pages of Git hosting providers.

Home Page: https://greasyfork.org/en/scripts?set=588773

License: GNU Affero General Public License v3.0

JavaScript 87.89% HTML 10.80% Shell 1.32%
git userscript userscripts

copy-commit-reference-userscript's People

Contributors

rybak avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

copy-commit-reference-userscript's Issues

Add support for Gogs

Overview

Development of Gogs is done on GitHub. A public-ish mirror is available at https://try.gogs.io/gogs/gogs. Gitea and Forgejo are forks of Gogs.

Public instances

Example URLs for testing

Screenshot

The button should be placed to the left of the "Browse Source" button, similar to implementation for GitHub and Gitea:

image

Add support for Forgejo

Overview

Forgejo is a fork of Gitea, with their own commits being continuously rebased on top of Gitea. Unlike Gitea, which is hosted on GitHub (they are working toward self-hosting, see pinned issues), Forgejo seems to be self-hosted: https://codeberg.org/forgejo/forgejo, since Codeberg runs Forgejo.

This was initially tracked under #4.

Public instances

Example URLs for testing

Screenshot

The button should be added to the left of "Browse Source", same as for Gitea, similar to GitHub.

image

Add support for Sourcehut

Overview

Is UI of this hosting provider a SPA?

No.

Public instances

Example URLs for testing

Screenshot

The userscript's button should go in the column of buttons on the right hand side:

image

Add support for Phorge

Overview

https://we.phorge.it/source/phorge/repository/master/

Phorge is a collection of web applications which help software companies build better software.

Phorge is a community-maintained fork of Phabricator.
...
Phorge is developed and maintained by The Phorge Team.

Is UI of this hosting provider a SPA?

No.

Public instances

Example URLs for testing

Screenshot

The userscript's button would fit well in the right hand sidebar:

image

Add support for Bitbucket Server

Overview

Is UI of this hosting provider a SPA?

No.

Public instances

There are none, as far as I am aware.

Example URLs for testing

N/A

Notes

Alpha version has a bunch of leftover code from bitbucket-copy-commit-reference.user.js of Atlassian Tweaks. Most of this leftover code is specific to supporting Bitbucket Server and Bitbucket Cloud.

We shall expand class BitbucketServer to fully implement support Bitbucket Server by reusing this leftover code.

Screenshots

v0.10-alpha, as of 2023-08-21. The button is on the left, near the permalink to the commit.
2023-08-21 bitbucket server screenshot

v0.17-alpha, as of 2023-08-25. The button is moved to the right, the checkmark tooltip is clipping out of page on the right.
2023-08-25 bitbucket server screenshot

v2.0, as of 2023-09-14. The tooltip is moved to the left and is now styled as some other native tooltips.
2023-09-14 bitbucket server screenshot

Extract common code into a library + Split into separate userscripts per Git hosting

Context

Long and boring historical context (click to expand)

The userscript copy-commit-reference.user.js originates from a userscript for Bitbucket Server. Bitbucket Server is the hosting that I use at $dayjob. That userscript is/was part of Atlassian Tweaks, where it is natural to also want to support Bitbucket Cloud, which it did since version 2, which was actually the initial commit for the userscript in that repository (version 1 supported only Bitbucket Server, but wasn't published).

For personal projects, I mostly use GitHub, so I've created a separate userscript for it as well.

Merging the two userscripts seemed like a good idea, because

  1. it allows for easier code re-use between the two userscripts, which was mostly done by copy-pasting
  2. it forces to come up with a better architecture for separating the common code from code specific to a particular Git hosting – this separation in the Bitbucket script between Cloud and Server versions was implemented terribly.

Once I had implementation for GitHub and Bitbucket Cloud (Bitbucket Server had to wait a bit), it was natural to want to add more. I started by adding GitWeb and Gitiles, because I was aware of repo.or.cz through its mirror of git.git (uses GitWeb) and I was aware of kernel.googlesource.com (uses Gitiles).

During development of copy-commit-reference.user.js, I've also figured out how to publish and use libraries for userscripts in a way that is compatible with rules of Greasy Fork.


As of version 2.3, the userscript supports eight different hostings, and there are plans to add seven more (15 in total, if all are implemented).

Problem

As of version 2.3, the userscript has size of 1.5K lines of code at roughly 54 kilobytes of JS. This seems like a bit of an overkill, if a user wants support for only one of the 8-15 supported hostings.

On the other hand, worrying about the code size is probably a premature optimization. For example, a fairly popular userscript – Stack Overflow Extras – is over 160 KB of JS, with 46+ KB of JSON, CSS, and HTML on top of that.

Solution

It might be a good idea to extract the common code of the userscript into a library, and replace the big userscript with 8-15 smaller separate userscripts, one userscript per Git hosting.

Pros

  • Smaller footprint, possibly leading to faster execution.
  • During publishing of a new version, users only need to update the userscripts relevant to them. For example:
  • More obvious/readable applicability to the user – each of the separate userscripts will just have the hosting in the name instead of the generic Git: copy commit reference.
  • Code simplification: a userscript for a single hosting doesn't need methods getLoadedSelector and isRecognized in the class GitHosting. This reduces the number of required methods from six to four.
  • Contributors, who want to work on existing support of a particular Git hosting need to edit a small file, unencumbered by all other irrelevant Git hostings.
  • It is an opportunity to get more experience for maintenance of libraries for userscripts.
  • A separate userscript could be in a different repository (how bitbucket-copy-commit-reference.user.js was/is in Atlassian Tweaks, see context above). A separate userscript could be even maintained by another person. This solves the problem of availability of the hostings for testing – a separate maintainer would be responsible for testing their userscript on the instances that they have access to themselves.
  • Easier to maintain up-to-date screenshots (cf. 52b8135 and 54d6c4a).
  • Git tags no longer need to be created in the main repository for the userscript (might still make sense to do it for the library).

Cons

  • If a user uses many hostings (as an example, I use Bitbucket Server, GitHub, and GitLab regularly) they have to install many userscripts
    • This also leads to multiple userscripts getting updated, if a change in the common code was published to all userscripts.
  • Harder to add support for new hostings. It would require creating infrastructure for a whole new userscript, which not all developers might be familiar with. This could be solved with some kind of template file.
  • More complicated and slower iteration, when changes in the common code are needed (add new feature to library > publish library > migrate userscript to new version of library > use new feature of library in userscript)
  • Support for userscript libraries in code editors is lacking. This means less information about types, worse auto-completion, etc.
    • However, this issue can be worked around at least in VS Code.
  • Increased maintenance burden for managing:
    • metadata of userscripts (the // ==UserScript== section at the top) (solvable with shell scripts)
    • documentation on Greasy Fork (solvable by storing it in the repo)
    • separate changelogs
  • Git tags will no longer be able to be created in a sensible manner – some users coming to a GitHub repo pay attention to presence or absence of recent releases/tags. Though this could be solved by introducing per-hosting tags: github-1.2, gitweb-3, bitbucket-server-4 etc.

Add support for Gitea

Overview

Gitea is a fork of Gogs (#8).

Is UI of this hosting provider a SPA?

No.

Public instances

Example URLs for testing

Screenshot

Gitea demo

TODO

Add support for Pagure

Overview

Is UI of this hosting provider a SPA?

No.

Public instances

Example URLs for testing

Screenshot

Not a lot of room on the right side, but it will fit if a simple icon is used. A mockup with clipboard emoji:

image

Font Awesome icons are also available, i.e. with HTML <span class="fa fa-copy"></span>, it looks like this:

image

GitHub: design change idea

Context

There are three components to the commit reference: hash, subject, and date. On GitHub, two of the are at the bottom of the commit's view (date and hash), and one is at the top (subject). On GitHub, as of version 0.8-alpha, the userscript puts the button (technically) in the bottom left corner, next to author information, which includes the date. The commit's hash is in the bottom right corner, next to a link to the parent commit.

Putting the button on the left (but not necessarily at the bottom) also mimics GitHub's own "Copy path to the file" button:

image

Idea

What if the button was on the left of the subject, next to the "Browse files" button?

Screenshot_20230816 GitHub idea

Add support for GitBucket

Overview

Is UI of this hosting provider a SPA?

No.

Public instances

Example URLs for testing

TODO

  • find a commit page with a body in the commit message

Screenshot

Not sure about the location yet, because of lack of a commit with a body in the commit message => I have no idea how the UI displays it. However, the button should probably be added to the left of button "Browse code":

image

Add support for RhodeCode

Overview

We might also consider supporting Kallithea, which is a fork of RhodeCode.

Public instances

Example URLs for testing

Screenshot

The button might fit well in the right hand side cluster of buttons, near the button "Copy the full commit id" and the permalink.

image

Put Markdown content into the clipboard

Many of the Git hostings support editing comments, issues, PR descriptions in Markdown syntax. It might be useful for the userscript to put content with type text/x-gfm into the clipboard.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.