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

Parse url for base branch and pr bases #5611

Merged
merged 2 commits into from
Nov 19, 2024
Merged

Conversation

mtsgrd
Copy link
Contributor

@mtsgrd mtsgrd commented Nov 19, 2024

  • will help us compare pr base against target

This is part 1 of 2 in a stack made with GitButler:

@vercel vercel bot temporarily deployed to Preview – gitbutler-web November 19, 2024 16:39 Inactive
Copy link

vercel bot commented Nov 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
gitbutler-components ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 19, 2024 7:33pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
gitbutler-web ⬜️ Skipped (Inspect) Nov 19, 2024 7:33pm

@vercel vercel bot temporarily deployed to Preview – gitbutler-web November 19, 2024 16:50 Inactive
@vercel vercel bot temporarily deployed to Preview – gitbutler-web November 19, 2024 17:12 Inactive
@vercel vercel bot temporarily deployed to Preview – gitbutler-web November 19, 2024 18:34 Inactive
@vercel vercel bot temporarily deployed to Preview – gitbutler-web November 19, 2024 19:18 Inactive
@mtsgrd
Copy link
Contributor Author

mtsgrd commented Nov 19, 2024

@Caleb-T-Owens what do you think of this the UniqueDerived class? I think we discussed this last week.

Copy link
Member

@krlvi krlvi left a comment

Choose a reason for hiding this comment

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

didnt properly review this but if it sucks we can fix it tomorro

@@ -0,0 +1,75 @@
import { writable, type Readable } from 'svelte/store';

export function uniqueDerived<T>(source: Readable<T>) {
Copy link
Contributor

@Caleb-T-Owens Caleb-T-Owens Nov 19, 2024

Choose a reason for hiding this comment

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

I'm not sure the class is helpful, can't we just say:

export function shallowDeduplicate<A>(store: Readable<A>): Readable<A> {
	const deduplicatedStore = readable(get(store), (set) => {
		let lastValue = get(store);
		const unsubscribe = store.subscribe((value) => {
			if (!shallowCompare(lastValue, value)) {
				lastValue = value;
				set(value);
			}
		});
		return unsubscribe;
	});

	return deduplicatedStore;
}

Copy link
Contributor Author

@mtsgrd mtsgrd Nov 19, 2024

Choose a reason for hiding this comment

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

Let me try that out. *edit: one immediate thing I would want to avoid is subscribing to the store when creating the derived store, which happens here because of the get() method.

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be safe to set the readable initial value to undefined, and keep the result as Readable<T> because the start stop notifier gets run synchronously

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... or even write it as a derived to make that intent clearer

Copy link
Contributor

Choose a reason for hiding this comment

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

export function shallowDeduplicate<A>(store: Readable<A>): Readable<A> {
	let lastValue: undefined | A = undefined;
	const deduplicatedStore = derived<Readable<A>, A>(store, (value, set) => {
			if (!shallowCompare(lastValue, value)) {
				lastValue = value;
				set(value);
			}
	});

	return deduplicatedStore;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

AHHhhhh no... that derived version isn't safe

@mtsgrd mtsgrd merged commit 4c212cd into master Nov 19, 2024
16 checks passed
@mtsgrd mtsgrd deleted the parse-base-and-pr-urls branch November 19, 2024 19:52
Comment on lines +55 to +57
if (typeof left !== 'object' || typeof right !== 'object' || left === null || right === null) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

undefined needs to be considered here

Comment on lines -28 to -43

const httpRemoteUrls = ['https://github.com/user/repo.git', 'http://192.168.1.1/user/repo.git'];

test.each(httpRemoteUrls)('HTTP Remote - %s', (remoteUrl) => {
expect(remoteUrlIsHttp(remoteUrl)).toBe(true);
});

const nonHttpRemoteUrls = [
'git@github.com:user/repo.git',
'ssh://git@github.com:22/user/repo.git',
'git://github.com/user/repo.git'
];

test.each(nonHttpRemoteUrls)('Non HTTP Remote - %s', (remoteUrl) => {
expect(remoteUrlIsHttp(remoteUrl)).toBe(false);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we want these tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because they existed for exactly 1 location in the code asking "is the protocol http?". The if condition can just as well be protocol.startsWith('http') rather than having a specialized and tested function.

@Caleb-T-Owens
Copy link
Contributor

didnt properly review this but if it sucks we can fix it tomorro

I'm bothered by this. Especially when I was asked for feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants