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

[Bug]: Plugin is pushing to Github a ref that already exists instead of a new one #265

Closed
3 tasks done
kurko opened this issue Dec 28, 2023 · 8 comments
Closed
3 tasks done
Assignees
Labels
🐛 Bug Something isn't working

Comments

@kurko
Copy link
Contributor

kurko commented Dec 28, 2023

Issue validation

  • I checked the issue to prevent duplicate
  • I checked my configurations files and the documentation
  • My issue concern doesn't concern the Mkdocs template

Command used

Upload single current active note

Plugin version

6.12.5

Describe the bug

I can't push files anymore. I was using v4.x of the plugin, then decided to upgrade to v6.x and no changes are pushed to Github anymore.

A few points:

  • the branch is created remotely
  • the plugin pushes a commit that already exists on the repo (which I created).
    • Based solely on my gut feeling, it seems like no new commit is being created locally in order push new changes because the payload always includes the same commit sha.
  • I don't really know what directory the repo is cloned to locally, so I couldn't go in there and figure out what's going on.
  • uninstalled/reinstalled the plugin, but problem persists. I wanted to cleanup any local repos.

Possible candidate: a couple weeks ago I reset a commit from main in my repo (git reset --hard HEAD~1 && git push -f), and I suspect the plugin's cloned version got out of sync. The thing is, I don't know how it keeps a version of the repo locally, whether it clones every time, or whether it keeps a version locally.

How to reproduce ?

The repo in question is https://github.com/kurko/blog. Current's main head commit is 9cd6e9.

  1. Use the test markdown provided in the issue form.
  2. Run Upload single current active note
  3. I already had the branch Primary-12-28-2023, so it errors out (as expected, I guess).
Screenshot 2023-12-28 at 18 45 58
  1. I proceed to delete the branch on Github
Screenshot 2023-12-28 at 18 45 18
  1. Run Upload single current active note again.
Screenshot 2023-12-28 at 18 46 43

Nothing happens. Note that it creates the branch and doesn't push any new commit. It just sets the sha as 9cd6e9, the same as HEAD in main.

  1. Run Upload single current active note once more. This time it errors out because it's trying to push a commit that already exists.
Screenshot 2023-12-28 at 18 58 23 Screenshot 2023-12-28 at 18 58 26

Given no new commits are pushed, it looks like the plugin is not identifying changes.

Minimal Reproducible Example

---
title: "Test"
share: true
---

# Test
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

Configuration

{
  "github": {
    "branch": "main",
    "automaticallyMergePR": false,
    "tokenPath": "%configDir%/plugins/%pluginID%/env",
    "api": {
      "tiersForApi": "Github Free/Pro/Team (default)",
      "hostname": ""
    },
    "workflow": {
      "commitMessage": "[PUBLISHER] Merge",
      "name": ""
    },
    "verifiedRepo": true
  },
  "upload": {
    "behavior": "fixed",
    "defaultName": "obsidian",
    "rootFolder": "",
    "yamlFolderKey": "",
    "frontmatterTitle": {
      "enable": true,
      "key": "filename"
    },
    "replaceTitle": [
      {
        "type": "title"
      }
    ],
    "replacePath": [
      {
        "regex": "",
        "replacement": "",
        "type": "path"
      }
    ],
    "autoclean": {
      "enable": true,
      "excluded": ""
    },
    "folderNote": {
      "enable": false,
      "rename": "index.md",
      "addTitle": {
        "enable": false,
        "key": "filename"
      }
    },
    "metadataExtractorPath": ""
  },
  "conversion": {
    "hardbreak": false,
    "dataview": true,
    "censorText": [
      {
        "entry": "/(?<!\\`)(?<!!)\\[(.*)\\]\\((?!(http|\\/*image|obsidian\\/image))(\\.\\/)*(.+?)(\\.md)*(#anchor)?\\)/",
        "replace": "[$1]({% link obsidian/$4.md %}$6)",
        "inCodeBlocks": false
      },
      {
        "entry": "/(?<!\\`)\\[(.*?)\\]\\(((obsidian\\/)?image)(.+)\\)/",
        "replace": "[$1](/image$4)",
        "inCodeBlocks": false
      }
    ],
    "tags": {
      "inline": false,
      "exclude": [],
      "fields": []
    },
    "links": {
      "internal": false,
      "unshared": false,
      "wiki": false,
      "slugify": false
    }
  },
  "embed": {
    "attachments": true,
    "overrideAttachments": [],
    "keySendFile": [
      "obsidian"
    ],
    "notes": false,
    "folder": "images/obsidian",
    "convertEmbedToLinks": "keep",
    "charConvert": "->",
    "forcePushAttachments": []
  }
}

Relevant log output

Failed to load resource: the server responded with a status of 422 ()
plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](pr.eval):
 Branch already exists (Primary-12-28-2023 on kurko/blog - Using it.
plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](pr.eval):
 Branch successfully created (status: 201) on kurko/blog
api.github.com/repos/kurko/blog/git/refs:1     Failed to load resource: the server responded with a status of 422 ()
plugin:obsidian-mkdocs-publisher:21 [GitHub Publisher](pr.eval):
 Branch already exists (Primary-12-28-2023 on kurko/blog - Using it.

OS

MacOS

Anything else?

No response

Obsidian information

SYSTEM INFO:
	Obsidian version: v1.5.3
	Installer version: v1.4.16
	Operating system: Darwin Kernel Version 23.2.0: Wed Nov 15 21:59:33 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8112 23.2.0
	Login status: logged in
	Catalyst license: insider
	Insider build toggle: off
	Live preview: off
	Base theme: light
	Community theme: obsidian_ia
	Snippets enabled: 1
	Restricted mode: off
	Plugins installed: 13
	Plugins enabled: 9
		1: Mind Map v1.1.0
		2: Tag Wrangler v0.5.3
		3: Metadata Extractor v1.0.2
		4: Dataview v0.5.46
		5: Force note view mode v1.1.1
		6: Obsidian42 - BRAT v0.6.35
		7: Reading Time v1.1.1
		8: Local images v0.14.2
		9: Github Publisher v6.12.5

RECOMMENDATIONS:
	Custom theme and snippets: for cosmetic issues, please first try updating your theme and disabling your snippets. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community theme and snippets.
	Community plugins: for bugs, please first try updating all your plugins to latest. If still not fixed, please try to make the issue happen in the Sandbox Vault or disable community plugins.
@kurko kurko added the 🐛 Bug Something isn't working label Dec 28, 2023
@kurko
Copy link
Contributor Author

kurko commented Dec 28, 2023

Extra thing: I removed all regex entries I had in settings, and no success. It is showing an error though (which isn't showing up in the console):

Screenshot 2023-12-28 at 19 04 04

@Mara-Li
Copy link
Member

Mara-Li commented Dec 28, 2023

Oh wow.
The bug is pretty difficult to reproduce this time.
To better understand, you need to know that nothing is done in local. Everything is done with the github api.

Do you have tried to delete the branch created by the plugin to test a new one ?

Normally, the plugin should use a branch that already exists as I generate a specific branch name at each push.

The bug with the regex is a nice catch. I know what happens here.

I will try to add some "try/except" Until we found the error, but you will need to try multiple main.js file to help me to find the error

@Mara-Li
Copy link
Member

Mara-Li commented Dec 28, 2023

Replace the file of the plugin by this :
plugin.zip

@kurko
Copy link
Contributor Author

kurko commented Dec 29, 2023

Thanks for the file. Unfortunately, nothing new, it's still showing the same error.

The file from the .zip is minified so I can't really change it. I'm going to try to get a dev version from the repo 🤞

I will try to add some "try/except" Until we found the error

Sounds good. Looking at the source in the console, there's just a lot of replace(...) occurrences, so this is going to be hard. It would be ideal if we had an easier way to add these breakpoints.

Screenshot 2023-12-28 at 21 43 16

I'll add a bunch of breakpoints and see if I can spot the location it fails.

Do you have tried to delete the branch created by the plugin to test a new one?

Yes, I did. One of the screenshots above is me deleting the created branch (see the orange marker)

The bug with the regex is a nice catch. I know what happens here.

🙇

To better understand, you need to know that nothing is done in local. Everything is done with the github api.

Interesting. But it has to commit the changes somewhere, is that via Github's API? I've never seen that feature, hence why I assumed it was local.

p.s did you close Discord? Can't find it (and the invite link in ko-fi.com seems to be invalid).

@kurko
Copy link
Contributor Author

kurko commented Dec 29, 2023

Found the spot where the error occurs 🕺

  1. this image shows the exact spot where the object on which replace is called is null (t).
Screenshot 2023-12-28 at 21 57 52
  1. stepping up the stack (going to the function that called Te(t)), we find this:
Screenshot 2023-12-28 at 21 58 39

Note how t in image 1 is really d, which is a configuration for dataview (d = l.settings.dataviewJsKeyword).

  1. I let it run and immediately get the error, confirming the location:
Screenshot 2023-12-28 at 22 00 43

I don't know where this is supposed to be set. Checking the codebase for occurrences of dataviewJsKeyword, only one occurrence comes up, this line https://github.com/ObsidianPublisher/obsidian-github-publisher/blob/ee4df6fb500a63f898cbb2d59dded59cc44d1fba/src/conversion/compiler/dataview.ts#L44 🤔

That configuration is expected, but (a) I don't think the settings UI is setting, and (b) I don't think it's set anywhere in the whole plugin.

@kurko
Copy link
Contributor Author

kurko commented Dec 29, 2023

Got it to work 😅 by adding this

Screenshot 2023-12-28 at 22 13 35

After this, Force Reloaded and it published. You can see the Pull Request was created.

@Mara-Li
Copy link
Member

Mara-Li commented Dec 29, 2023

Wow! Ty!

And yes; I closed the discord!
I think that using Github is better because Discord doesn't allow user to do Google research. Not good for archive!

Some reply to your question:

  • dataviewJsKeyword is a setting of Dataview. I added the default key dataviewjs if not are found.
  • Everything is made online by the GitHub API "octokit". In fact, I make a “save” of the transformed file, and send it like a commit in a branch. (Sorry I don't know how to explain this). Octokit allows creating file on the flow without having the file on your computer.

To be honest, I don't understand why a crash during the process of dataview (did you have the last version ?) could provoc all things!

@kurko
Copy link
Contributor Author

kurko commented Dec 29, 2023

Thank you

I added the default key dataviewjs if not are found.

This commit I suppose? 5328c58 Will test later and report back.

I don't understand why a crash during the process of dataview (did you have the last version ?)

I do have the latest version. I guess there's just too many variables that can be null or undefined in the codebase, so it makes sense to always apply some defensive programming and cover for those cases.

@kurko kurko closed this as completed Dec 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants